我正在尝试创建两个不同的系列但是如果我运行宏,第二个系列不幸地会覆盖第一个系列。所以最后,我的图表中只有第二个系列。有人可以帮忙吗?
With ChtObj
'Series LTU
Set Ser = .Chart.SeriesCollection.NewSeries
With Ser
.Name = "=" & Dataws.Cells(CurrentRow, 1).Address(False, False, xlA1, xlExternal)
.XValues = "=" & Dataws.Cells(CurrentRow, 3).Address(False, False, xlA1, xlExternal)
.Values = "=" & Dataws.Cells(CurrentRow, 4).Address(False, False, xlA1, xlExternal)
End With
'Series LTA
With Ser
.Name = "LTA_" & Dataws.Cells(CurrentRow, 1)
.XValues = "=" & Dataws.Cells(CurrentRow, 3).Address(False, False, xlA1, xlExternal) & "," & Dataws.Range(Dataws.Cells(CurrentRow, 14), Dataws.Cells(CurrentRow, 22)).Address(False, False, xlA1, xlExternal)
.Values = "=" & Dataws.Cells(CurrentRow, 4).Address(False, False, xlA1, xlExternal) & "," & Dataws.Range(Dataws.Cells(CurrentRow, 42), Dataws.Cells(CurrentRow, 50)).Address(False, False, xlA1, xlExternal)
End With
End With
谢谢!
答案 0 :(得分:2)
问题是您使用相同的Ser
,因此将其替换。
With ChtObj
Set Ser = .Chart.SeriesCollection.NewSeries
With Ser
.Name = "=" & Dataws.Cells(CurrentRow, 1).Address(False, False, xlA1, xlExternal)
.XValues = "=" & Dataws.Cells(CurrentRow, 3).Address(False, False, xlA1, xlExternal)
.Values = "=" & Dataws.Cells(CurrentRow, 4).Address(False, False, xlA1, xlExternal)
End With
'Series LTA
Set Ser = .Chart.SeriesCollection.NewSeries
With Ser
.Name = "LTA_" & Dataws.Cells(CurrentRow, 1)
.XValues = "=" & Dataws.Cells(CurrentRow, 3).Address(False, False, xlA1, xlExternal) & "," & Dataws.Range(Dataws.Cells(CurrentRow, 14), Dataws.Cells(CurrentRow, 22)).Address(False, False, xlA1, xlExternal)
.Values = "=" & Dataws.Cells(CurrentRow, 4).Address(False, False, xlA1, xlExternal) & "," & Dataws.Range(Dataws.Cells(CurrentRow, 42), Dataws.Cells(CurrentRow, 50)).Address(False, False, xlA1, xlExternal)
End With
End With
尝试再次定义新系列或为Series2使用其他名称。