moving graph using macro
I have added a macro that will collect data and add a graph to my worksheet. Because users will be able to run this macro at any time and repeat the action indefinitely, the chart's name is always changing, e.g. "Chart 23", "Chart 24". After the chart is built I want to move the chart within the worksheet and resize it.
When I record the macro the code is:
ActiveSheet.Shapes("Chart 48").IncrementLeft -212.25
ActiveSheet.Shapes("Chart 48").ScaleWidth 1.52, msoFalse, msoScaleFromTopLeft
I have set a variable to capture the chart's name and it does so successfully (chartname1 = ActiveChart.Name). When I try to insert this into the code, however, it doesn't work.
ActiveSheet.Shapes(chartname1).IncrementLeft -212.25
ActiveSheet.Shapes(chartname1).ScaleWidth 1.52, msoFalse, msoScaleFromTopLeft
The debug says it can't find the object.
Any ideas on how to write this w/o a static chart name?
|