/ / VBA:チャートで系列を作成する - excel、vba、excel-vba、excel-formula

VBA:チャートで系列を作成する - excel、vba、excel-vba、excel-formula

私は2つの異なるシリーズを作成しようとしていますが私は、残念ながら、2番目のシリーズが最初のマクロを上書きし続けるマクロを実行します。それで、最後に、私は私のチャートに2番目のシリーズしかありません。誰も手伝ってくれる?

     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

ありがとうございました!

回答:

回答№1は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に別の名前を使用してください。