だから、このようなものが私のために働いた. CopyCharts は、すべてのグラフをソース シートからターゲット シートにコピーします。次に、SetChartRef は、ターゲット内のチャートの参照を希望するものに設定します。この例では、どのチャート番号が何であるかを知っています。代わりにチャート名を使用するように改善できると思います。
また、何らかの理由で、コピーと貼り付けの間に遅延がない場合、実行時エラーが発生するため、待機機能が発生します。
Sub DeleteEmbeddedCharts(target As String)
Dim wsItem As Worksheet
Dim chtObj As ChartObject
For Each chtObj In ThisWorkbook.Worksheets(target).ChartObjects
chtObj.Delete
Next
End Sub
Sub SetChartRef(target As String)
Dim cht As ChartObject
Dim i As Integer
'i specifies which chart to set its data references
i = 0
For Each cht In ThisWorkbook.Worksheets(target).ChartObjects
If i = 0 Then
cht.Chart.SeriesCollection(1).Values = "=" & target & "!$I$2:$I$12"
cht.Chart.SeriesCollection(2).Values = "=" & target & "!$J$2:$J$12"
ElseIf i = 1 Then
cht.Chart.SeriesCollection(1).Values = "=" & target & "!$I$14:$I$25"
cht.Chart.SeriesCollection(2).Values = "=" & target & "!$J$14:$J$25"
ElseIf i = 2 Then
cht.Chart.SeriesCollection(1).Values = "=" & target & "!$I$26:$I$37"
cht.Chart.SeriesCollection(2).Values = "=" & target & "!$J$26:$J$37"
ElseIf i = 3 Then
cht.Chart.SeriesCollection(1).Values = "=(" & target & "!$H$2," & target & "!$H$14," & target & "!$H$26," & target & "!$H$38)"
cht.Chart.SeriesCollection(1).XValues = "=(" & target & "!$E$2," & target & "!$E$14," & target & "!$E$26," & target & "!$E$38)"
ElseIf i = 4 Then
cht.Chart.SeriesCollection(1).Values = "=(" & target & "!$H$2," & target & "!$H$14," & target & "!$H$26," & target & "!$H$38)"
cht.Chart.SeriesCollection(1).XValues = "=(" & target & "!$E$2," & target & "!$E$14," & target & "!$E$26," & target & "!$E$38)"
ElseIf i = 5 Then
cht.Chart.SeriesCollection(1).Values = "=" & target & "!$I$38:$I$49"
cht.Chart.SeriesCollection(2).Values = "=" & target & "!$J$38:$J$49"
End If
i = i + 1
Next
End Sub
Sub CopyCharts(source As String, target As String)
Dim chtObj As ChartObject
'First delete all charts from target sheet
DeleteEmbeddedCharts (target)
'Some delay
Application.Wait Now + TimeSerial(0, 0, 1)
For Each chtObj In ThisWorkbook.Worksheets(source).ChartObjects
With ThisWorkbook.Worksheets(target)
.Activate
chtObj.Copy
'Paste in row T1+i
Range("T1").Offset(i).Select
.Activate
Application.Wait Now + TimeSerial(0, 0, 1)
.Paste
Application.Wait Now + TimeSerial(0, 0, 1)
i = i + 10
.Activate
End With
Next chtObj
'Set the data references to target sheet
SetChartRef (target)
End Sub