【发布时间】:2016-03-02 03:31:57
【问题描述】:
更新:我稍微修改了尼克建议的代码。最初,这个带有 Rng.Offset 的代码需要大范围的数据来制作雷达图。例如:从 (A1:E1):(A2:E2) (这第一个很好),但后来它去了: (A1:E1):(A3:E3), (A1:E1):(A4:E4) , (A1:E1):(A5:E5), 等等...相反,我试图每次只选择一个额外的行,因此:(A1:E1)+(A3:E3), (A1:E1 )+(A4:E4), (A1:E1)+(A5:E5)。
Sub MultipleRadarCharts()
Dim i As Integer
Dim Rng As Range
Set Rng = Sheets("Indices4Pilares (4)").Range("A1:E1")
For i = 2 To 36
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlRadarMarkers
'ActiveChart.SetSourceData Source:=Sheets("Indices4Pilares (4)").Range(Rng, Rng.Offset(i - 1, 0))
'ActiveChart.SetSourceData Source:=Sheets("Indices4Pilares (4)").Range(Rng, Range(Cells(i, 1), Cells(i, 5)))
ActiveChart.SetSourceData Source:=Sheets("Indices4Pilares (4)").Union(Range(Cells(1, 1), Cells(1, 5)), Range(Cells(i, 1), Cells(i, 5))).Select
ActiveChart.Legend.Delete
Next i
Set Rng = Nothing
End Sub
=====
:) 我刚刚创建了这段代码,以便从 Excel 表中获取雷达图。
第一行是变量的名称,然后(从第 2 行到第 36 行)是值。问题是我一直试图用“for循环”来简化代码,但我无法让它工作:(
这是我要简化的原始代码...
Sub Macro2()
Range("A1:E1,A2:E2").Select
Range("A2").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlRadarMarkers
ActiveChart.SetSourceData Source:=Range( _
"'Indices4Pilares (3)'!$A$1:$E$1,'Indices4Pilares (3)'!$A$2:$E$2")
ActiveChart.Legend.Select
Selection.Delete
Range("A1:E1,A3:E3").Select
Range("A3").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlRadarMarkers
ActiveChart.SetSourceData Source:=Range( _
"'Indices4Pilares (3)'!$A$1:$E$1,'Indices4Pilares (3)'!$A$3:$E$3")
ActiveChart.Legend.Select
Selection.Delete
Range("A1:E1,A4:E4").Select
Range("A4").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlRadarMarkers
ActiveChart.SetSourceData Source:=Range( _
"'Indices4Pilares (3)'!$A$1:$E$1,'Indices4Pilares (3)'!$A$4:$E$4")
ActiveChart.Legend.Select
Selection.Delete
Range("A1:E1,A5:E5").Select
Range("A5").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlRadarMarkers
ActiveChart.SetSourceData Source:=Range( _
"'Indices4Pilares (3)'!$A$1:$E$1,'Indices4Pilares (3)'!$A$5:$E$5")
ActiveChart.Legend.Select
Selection.Delete
End Sub
【问题讨论】: