0

複数のワークシートのデータを含むグラフを同じグラフにプロットしようとしています。したがって、各シートのデータは、私のグラフでは別々のシリーズになります。2枚のサンプルコードは次のとおりです。

Name1 = ActiveWorkbook.Worksheets(1).Name
Name2 = ActiveWorkbook.Worksheets(2).Name

ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.ChartArea.Select

ActiveChart.SeriesCollection.NewSeries

ActiveChart.SetSourceData Source:=Range("'" & Name1 & "'!$C$" & nStart & ":$D$" & nLast & "")
ActiveChart.SeriesCollection(1).Name = "=" & Name1 & "!A1"
ActiveChart.SeriesCollection(1).XValues = "='" & Name1 & "'!$C$" & nStart & ":$C$" & nLast & ""
ActiveChart.SeriesCollection(1).Values = "='" & Name1 & "'!$E$" & nStart & ":$E$" & nLast & ""

ActiveChart.SeriesCollection.NewSeries
ActiveChart.SetSourceData Source:=Range("'" & Name2 & "'!$C$" & nStart & ":$D$" & nLast & "")
ActiveChart.SeriesCollection(2).XValues = "='" & Name2 & "'!$C$" & nStart & ":$C$" & nLast & ""
ActiveChart.SeriesCollection(2).Values = "='" & Name2 & "'!$E$" & nStart & ":$E$" & nLast & ""
ActiveChart.SeriesCollection(2).Name = "=" & Name2 & "!A1"

しかし、2番目のシリーズコレクションで「無効なパラメータ」エラーが発生します。これを解決するのを手伝ってください。

ありがとう!

4

1 に答える 1

0

2番目のシリーズコレクションのコード行をコメントアウトして、ActiveChart.SetSourceData Source:=Range("'" & Name2 & "'!$C$" & nStart & ":$D$" & nLast & "")それが機能するかどうかを確認してください。

ActiveChart.SetSourceDataシリーズの値を具体的に定義しているので、コードの最初の行も必要ありません。

これらのコード行を追加して、グラフに名前を付けることもできます。これは、2番目のシリーズを追加すると上書きされるためです。

ActiveChart.SetElement (msoElementChartTitleAboveChart)
Selection.Caption = "NameOfChart"

お役に立てば幸い

于 2012-10-17T02:00:22.260 に答える