Reputation: 966
I have a macro to create a chart and modify its properties.
If I run the macro normally, I get
Run-time error '-2147024809 (80070057)':
The Item with the specified name wasn't found.
on the last line of this code
Set ChtObj = Worksheets("summary").ChartObjects.Add(Left:=700, Top:=100, Width:=800, Height:=500)
With ChtObj
.chart.ChartType = xlColumnStacked
.chart.SetSourceData Source:=Range("statistics!A101:C" & targetRow)
.Name = "waterfall"
End With
ActiveSheet.ChartObjects("waterfall").Activate
If I run the code step by step, I get no errors.
Upvotes: 3
Views: 2112
Reputation: 43595
Write Worksheets("summary").Activate
on the top of your code, it should work.
The problem is that during the macro running, your active sheet is not "summary". In general, using Activesheet
is not a good practice in VBA - How to avoid using Select in Excel VBA.
Upvotes: 3