我有一个生成两列数据的 VBA 代码。重复此分析以在相同列中生成更多数据,但条件不同,并将此数据放在第一次迭代的输出下方。如何获取代码以在生成的每个数据块旁边生成带有平滑线的 XY 散点图?我的尝试如下,但是我遇到了三个问题:1)在调试停止宏之前它只生成一个图,2)它生成一个条形图而不是散点图 3)我如何获得每个生成的图以按比例放置在它从中提取的数据旁边,我得到一列图表?
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