我正在尝试使用数据透视表中的VBA创建图表。我的代码如下:
Sub chart()
'
' chart Macro
'
'
Range("B5:E5").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Range("Pivot!$A$3:$E$5")
ActiveSheet.Shapes("Chart 4").LockAspectRatio = msoTrue
ActiveChart.ShowValueFieldButtons = False
ActiveSheet.ChartObjects("Chart 4").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyDataLabels
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).ApplyDataLabels
ActiveChart.SeriesCollection(3).Select
ActiveChart.SeriesCollection(3).ApplyDataLabels
End Sub
在这里为ActiveSheet.Shapes("Chart 4").LockAspectRatio = msoTrue
创建一个变量或全局变量(图4),以便下次不会显示任何错误。
该如何解决?