So something like this worked for me. CopyCharts copies all charts from a source sheet to a target sheet. Then SetChartRef sets the reference of the charts in the target to what I want them to be. In this example I know which chart number is what. I guess it can be improved so that it uses the chart names instead.
Also, for some reason I get run time errors if I don't have delays between copying and pasting, hence the wait functions.
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
perhaps a macro ...
Sure there could be a macro. If you would like help with one, please post the code you've tried and we can help much more effectively. However, I would offer that unless you have an incredible amount of sheets to copy, or need to do it over and over again, doing it the way you've found may be best. – Scott Holtzman.SetSourceData
to change the source. Give it a try and if you are stuck then post the code that you tried and we will take it form there :) – Siddharth Rout