I'm trying to move all charts from source sheet to destination sheet. The following code works fine when I run it from the VB Editor. My source had two charts and both were successfully moved.
But when I try to run it using a form button from a third sheet (neither source nor destination, it only works for the first chart and then returns an error. Infuriatingly it retains a copy of the 'moved' chart in the source as well.
The code gets stuck inside the loop and returns a "The specified dimension is not valid for the current chart type" error.
But when I try to run it using a form button from a third sheet (neither source nor destination, it only works for the first chart and then returns an error. Infuriatingly it retains a copy of the 'moved' chart in the source as well.
VBA Code:
Sub moveAllCharts(source As String, destination As String)
Dim chartObject As Object
ActiveWorkbook.Worksheets.Add(After:=Application.Worksheets(source)).Name = destination
For Each chartObject In Worksheets(source).ChartObjects
chartObject.Chart.Location xlLocationAsObject, destination
Next chartObject
End Sub
The code gets stuck inside the loop and returns a "The specified dimension is not valid for the current chart type" error.