0
votes

I get duplicate Pasted Charts when I run the macro. What it does, goes through all excel sheets and copies the available charts, then pastes them on the ChartObjects page.

Do you see the error? Can you help with correction?

Sub Test1()

Dim cht As Excel.ChartObject

Worksheets("ChartObjects").ChartObjects.Delete

For Each Sheet In ActiveWorkbook.Worksheets
If Sheet.Name <> "ChartObjects" Then

Sheet.Select
For Each cht In Sheet.ChartObjects

cht.Select
cht.Copy

Sheets("ChartObjects").Select
Range("C5").Select
ActiveSheet.Paste

Next

End If
Next Sheet

End Sub
1

1 Answers

2
votes

You need to exclude ChartObjects from the For Each loop.

For Each Sheet In ActiveWorkbook.Worksheets
  If Sheet.Name<>"ChartObjects" Then
    'your code
  End if
Next Sheet