Hi, I have previously created a chart and copied it to another sheet. But now I have added a text box and grouped the text box and chart together (not in VBA). I want to be able to copy the group to another sheet as a picture. I believe instead of "Chart" it's "Shape" in VBA. But I don't know how to write the code. Now my code is like this. I have highlighted the parts that I believe should be changed. And I would like to keep the With...end with -statement because it seems working well.
Sub CreateCharts ()
Dim wsData As Worksheet
Dim wsPIA As Worksheet
Dim rngDst As Range
Dim chtCx As ChartObject
Dim loData As ListObject
'Get reference
Set wsData = ThisWorkbook.Worksheets("Data")
Set wsPIA = ThisWorkbook.Worksheets("PIA")
Set loData = wsData.ListObjects("Table1")
'Filter data
loData.Range.AutoFilter Field:=11, Criteria1:="France"
'CopyPaste boxplot chart
With ThisWorkbook.Worksheets("Sales")
CopyChart wsPIA.ChartObjects("Country"), .Range("B2"), "France_Country"
End With
End Sub
Private Sub CopyChart(Cht As ChartObject, rngDst As Range, ChtName As String)
Dim o As Object
rngDst.Worksheet.Activate
rngDst.Cells(1, 1).Select
Cht.CopyPicture
rngDst.Worksheet.Pictures.Paste.Name = ChtName
End Sub
Sub CreateCharts ()
Dim wsData As Worksheet
Dim wsPIA As Worksheet
Dim rngDst As Range
Dim chtCx As ChartObject
Dim loData As ListObject
'Get reference
Set wsData = ThisWorkbook.Worksheets("Data")
Set wsPIA = ThisWorkbook.Worksheets("PIA")
Set loData = wsData.ListObjects("Table1")
'Filter data
loData.Range.AutoFilter Field:=11, Criteria1:="France"
'CopyPaste boxplot chart
With ThisWorkbook.Worksheets("Sales")
CopyChart wsPIA.ChartObjects("Country"), .Range("B2"), "France_Country"
End With
End Sub
Private Sub CopyChart(Cht As ChartObject, rngDst As Range, ChtName As String)
Dim o As Object
rngDst.Worksheet.Activate
rngDst.Cells(1, 1).Select
Cht.CopyPicture
rngDst.Worksheet.Pictures.Paste.Name = ChtName
End Sub