Public Sub CopyCharts()
Const strSHEET_WITH_CHARTS = "Sheet1" '<--- Set name of sheet containing charts
Dim intCounter As Integer
Dim wksTarget As Worksheet
Dim chtObj As ChartObject
On Error GoTo ErrorHandler
For Each chtObj In ThisWorkbook.Sheets(strSHEET_WITH_CHARTS).ChartObjects
Set wksTarget = CreateWorksheet(chtObj.Chart.ChartTitle.Text)
chtObj.Copy
wksTarget.Paste
intCounter = intCounter + 1
Next chtObj
ThisWorkbook.Sheets(strSHEET_WITH_CHARTS).Activate
MsgBox intCounter & " chart(s) were copied.", vbInformation
ExitHandler:
Set wksTarget = Nothing
Set chtObj = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
Private Function CreateWorksheet(ByVal strSheetName As String) As Worksheet
Dim strNewName As String
Dim intCounter As Integer
strNewName = strSheetName
Do While SheetExists(strNewName)
intCounter = intCounter + 1
strNewName = strSheetName & " (" & intCounter & ")"
Loop
With ThisWorkbook.Sheets
Set CreateWorksheet = .Add(, .Item(.Count))
CreateWorksheet.Name = strNewName
End With
End Function
Private Function SheetExists(ByVal strSheetName As String) As Boolean
Dim objSheet As Object
On Error Resume Next
Set objSheet = ThisWorkbook.Sheets(strSheetName)
On Error GoTo 0
SheetExists = Not (objSheet Is Nothing)
Set objSheet = Nothing
End Function