我怎样才能使我的VBA包含第二系列的数据

当我使用下面的macros时,它只适用于一个系列数据集。 我怎样才能适应它,以便我可以包括多个系列?

目前,如果我尝试使用它来标记第二个集合,它将删除第一个,等等…

提前致谢

Sub AddXYLabels() If Left(TypeName(Selection), 5) <> "Chart" Then MsgBox "Please select the chart first." Exit Sub End If Set StartLabel = _ Application.InputBox("Click on the cell containing the first(top) label", Type:=8) Application.ScreenUpdating = False For Each pt In ActiveChart.SeriesCollection(1).Points pt.ApplyDataLabels xlDataLabelsShowValue pt.DataLabel.Caption = StartLabel.Value Set StartLabel = StartLabel.Offset(1) Next End Sub 

您的代码不适用于系列的其余部分,因为您只对一个系列的范围进行了硬编码

 For Each pt In ActiveChart.SeriesCollection(1).Points 

请试试这个

 Sub AddXYLabels() If Left(TypeName(Selection), 5) <> "Chart" Then MsgBox "Please select the chart first." Exit Sub End If Dim mySeries As Series Dim seriesCol As SeriesCollection Dim I As Integer I = 1 Set seriesCol = ActiveChart.SeriesCollection For Each mySeries In seriesCol Set mySeries = ActiveChart.SeriesCollection(I) With mySeries .ApplyDataLabels xlDataLabelsShowValue End With I = I + 1 Next End Sub