specific syntax query

richn

Board Regular
Joined
Nov 21, 2002
Messages
70
dear all

I have recorded a macro which basically just creates a chart in a standard style and resizes it to a uniform size. Here is a section of the code:

Code:
    ActiveChart.ChartArea.Select
    ActiveSheet.Shapes("Chart 18").IncrementLeft -179.25
    ActiveSheet.Shapes("Chart 18").IncrementTop 50.25
    ActiveChart.ChartArea.Select
    ActiveSheet.Shapes("Chart 18").ScaleWidth 0.7, msoFalse, msoScaleFromTopLeft
    ActiveSheet.Shapes("Chart 18").ScaleHeight 0.71, msoFalse, msoScaleFromTopLeft
    ActiveChart.Axes(xlValue).Select

My problem is that the code refers to a specific chart (chart 18), and therefore will only work if the chart is called 'chart18'. Could anybody adjust the syntax so that it resizes the chart to the same dimensions, but with whichever chart happens to be selected at the time.

I had a couple of guesses at what the syntax might be, but didn't get it!

Thanks in advance for your help

Rich
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

tactps

Well-known Member
Joined
Jan 20, 2004
Messages
3,460
You will need to select the chart first, but then this will do it:

Sub macro()
ChartName = Right(ActiveChart.Name, Len(ActiveChart.Name) - Len(ActiveSheet.Name) - 1)
ActiveChart.ChartArea.Select
ActiveSheet.Shapes(ChartName).IncrementLeft -179.25
ActiveSheet.Shapes(ChartName).IncrementTop 50.25
ActiveChart.ChartArea.Select
ActiveSheet.Shapes(ChartName).ScaleWidth 0.7, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes(ChartName).ScaleHeight 0.71, msoFalse, msoScaleFromTopLeft
ActiveChart.Axes(xlValue).Select
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,088
Messages
5,835,321
Members
430,351
Latest member
ddalton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top