Looking to tweak a macro that renames a chart

aa123

New Member
Joined
Aug 31, 2011
Messages
11
I'm currently in the middle of a project to create chart reports for multiple users.

Upon pressing a macro button, what I'd like it to do is the following:

- Create a chart
- Change the chart title
- Export the chart as an image

With the code I have, to change the chart title I need to input the chart number, but upon creating a chart it's assigned it's own number. Is there any way I can change the code so that it picks up the number of the most recently generated chart?

Here's the chart rename code:

Code:
ActiveSheet.ChartObjects("Chart ##").Activate
ActiveChart.ChartArea.Select
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = Range("a44").Value & " Conversion Rate"

I also have code for identifying the number of the chart, could this be used in some way?

Code:
Sub IdentifyChart()
Dim chtObject As ChartObject
For Each chtObject In ActiveSheet.ChartObjects
MsgBox chtObject.Name
Next
End Sub

Thanks in advance for any help.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I pasted it over the "ActiveSheet.ChartObjects("Chart ##").Activate" code, and it gives me an error saying:

Code:
Run-time error 424':
 
Object required

Any ideas?

I'm using Excel 2003.
 
Upvote 0
Sorry, it should be

Code:
ActiveSheet.ChartObjects(ActiveSheet.ChartObjects.Count).Activate
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,763
Members
452,940
Latest member
rootytrip

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
Back
Top