我有一個生成數據的兩個colums一個VBA代碼。這種分析重複產生在同一列,但對於不同的條件和場所的第一次迭代的輸出低於這個數據更多的數據。如何讓代碼生成生成的旁邊,每個數據塊中的XY散點圖與流暢的線條?我的嘗試是在下面,但是我遇到了三個問題:1)它只在調試停止宏之前生成一個圖形,2)它生成一個條形圖而不是散點圖3)如何獲得生成的每個圖形按比例放置在它正在繪製的數據旁邊,我得到一列圖表?自動數據範圍識別當繪製圖形的Excel VBA
Sub TestExample()
Dim NoIteration As Integer
Dim Iteration As Integer
NoIteration = Range("N26").Value
Dim YieldIteration As Integer
Dim NoOfJumps As Long
Dim minyield As Long
Dim maxyield As Long
Dim jump As Long
NoOfJumps = Range("Q24").Value
minyield = Range("Q25").Value
maxyield = Range("Q26").Value
jump = Range("Q27").Value
Dim xaxis As Range
Dim yaxis As Range
Dim c As Chart
Dim Sh As String
Sh = ActiveSheet.Name
Range("M29:T1000").Select
Selection.Clear
For jump = 0 To NoOfJumps
For Iteration = 0 To NoIteration
'Print Intervals
Range("M30").Offset(NoIteration + Iteration + 4, 0).Value = Range("V19").Value * Iteration
'Solve weights for minimum Spot SD for each given interval
SolverReset
SolverOk SetCell:="$T$18", MaxMinVal:=2, ValueOf:="0", ByChange:="$O$20:$R$20"
SolverAdd CellRef:="$T$17", Relation:=2, FormulaText:=Range("M30").Offset(NoIteration + Iteration + 4, 0).Value
SolverAdd CellRef:="$T$20", Relation:=2, FormulaText:=1
SolverAdd CellRef:="$T$7", Relation:=1, FormulaText:=minyield + jump 'State min required yield
SolverAdd CellRef:="$T$7", Relation:=3, FormulaText:=maxyield + jump 'State max required yield
SolverAdd CellRef:="$O$20:$R$20", Relation:=3, FormulaText:="0"
SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1
'Print Income Return, SD
Range("N30").Offset(Iteration + jump * 50, 0).Value = Range("T7").Value
Range("O30").Offset(Iteration + jump * 50, 0).Value = Range("T8").Value
'Print Spot Return, SD
Range("N30").Offset(NoIteration + Iteration + 4 + jump * 50, 0).Value = Range("T17").Value
Range("O30").Offset(NoIteration + Iteration + 4 + jump * 50, 0).Value = Range("T18").Value
'Print Total Return, SD
Range("N30").Offset(NoIteration * 2 + Iteration + 8 + jump * 50, 0).Value = Range("AC17").Value
Range("O30").Offset(NoIteration * 2 + Iteration + 8 + jump * 50, 0).Value = Range("AC18").Value
Next Iteration
Set yaxis = Range(Range("N30").Offset(Iteration + jump * 50, 0), Range("N30").End(xlDown))
Set xaxis = Range(Range("O30").Offset(Iteration + jump * 50, 0), Range("$O30").End(xlDown))
Set c = ActiveWorkbook.Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=Sh
'Set c = c.Location(Where:=xlLocationAsObject, Name:="Sheet1")
With c
.ChartType = xlXYScatterLines
' set other chart properties
End With
Dim s As Series
Set s = c.SeriesCollection.NewSeries
With s
.Values = yaxis
.XValues = xaxis
End With
Next jump
End Sub
這就是我所需要的,但是我遇到的基本問題是查找數據來繪製圖表。正如空間分隔數據的原始代碼打印塊是得到中查找每個塊和第一個代碼經過一個循環地塊旁邊的圖形的代碼。我所遇到的一個問題是,如果我在上面的代碼中插入下面的代碼,它可以正常工作。但是,如果我「呼叫」它,它不。不知道爲什麼。由於下面的代碼只是更大代碼的一部分(它繪製了幾張圖),所以調用它會很有用。 – Mary
那麼,這是否意味着問題就解決了? –
是的,謝謝 - 我已將解決方案放在下面,請參閱srs.Xvalues/srs.Values部分。然而,它並不清楚爲什麼它不在通話下工作。 – Mary