我对宏很陌生,并且一直在使用 SQL 等更简单的语言。任何帮助将不胜感激!!
我很确定我的代码看起来很有趣~
目标:
- 图 COLUMN(H) AS X, COLUMN(I) AS Y
- 将列 (J) 评估为设置 4 个不同范围的行范围的值
- 范围1 <= 5, 5 <范围2 <= 10, 10 <范围3 <= 15, 范围4 > 15
- 在散点图上返回不同系列的相应范围
以下是我尝试过的宏:
Private Sub GRAPH()
Application.ScreenUpdating = False
FINALROW = Sheet1.Range("A65536").End(xlUp).Row
RowRange = Sheet1.Range(J2, "J" & FINALROW).Row
If RowRange <= 5 Then
ROW5 = WorksheetFunction.Max(Rows(H2, "H" & FINALROW)).Row
End If
If RowRange <= 10 Then
ROW10 = WorksheetFunction.Max(Rows(H2, "H" & FINALROW)).Row
End If
If RowRange <= 15 Then
ROW15 = WorksheetFunction.Max(Rows(H2, "H" & FINALROW)).Row
End If
sheetname = ActiveSheet.Name
Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Columns("H:I")
ActiveChart.SeriesCollection(1).XValues = Range("H" & ROW5, lastcell2)
ActiveChart.SeriesCollection(2).XValues = Range("H" & ROW10, lastcell2)
ActiveChart.SeriesCollection(3).XValues = Range("H" & ROW15, lastcell2)
ActiveChart.SeriesCollection(4).XValues = Range("H" & FINALROW, lastcell2)
ActiveChart.SeriesCollection(1).YValues = Range("I" & ROW5, lastcell2)
ActiveChart.SeriesCollection(2).YValues = Range("I" & ROW10, lastcell2)
ActiveChart.SeriesCollection(3).YValues = Range("I" & ROW15, lastcell2)
ActiveChart.SeriesCollection(4).YValues = Range("I" & FINALROW, lastcell2)
End Sub