VBA:在图表中创build系列

我试图创build两个不同的系列,但是如果我运行macros,第二个系列会不幸覆盖第一个系列。 所以最后,我只有我的图表中的第二个系列。 谁能帮忙?

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 

谢谢!

问题是你正在使用相同的Ser ,所以这被replace。

 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使用不同的名称。