#1   Report Post  
James
 
Posts: n/a
Default Chart Macro

Is there a way to record a macro when creating a chart and use the value of
A1 as the chart title and the value of A2 as the name of the chart.
Right now, when I look in the VBA editor the macro has recorded the name as
"chart 11" or something like that.
I've tried to use ActiveChart.Name = "James" as the name of the chart, but I
keep getting an error.
Can anyone please help me?
Thanks James
--

  #2   Report Post  
John Mansfield
 
Posts: n/a
Default

James,

Add this code to a standard module. Select the chart and then run the macro
(note: assumes you are referring to an embedded chart on Sheet1 of your
workbook).

Sub ChartMacro()
Dim Cht As Chart
Set Cht = ActiveChart
Cht.Parent.Name = Sheets("Sheet1").Range("A1").Value
Cht.ChartArea.Select
With Cht
.HasTitle = True
.ChartTitle.Characters.Text = Sheets("Sheet1").Range("A2").Value
End With
MsgBox "The chart name is: " & Cht.Parent.Name
MsgBox "The chart title is: " & Cht.ChartTitle.Characters.Text
End Sub

----
Regards,
John Mansfield
http://www.pdbook.com

"James" wrote:

Is there a way to record a macro when creating a chart and use the value of
A1 as the chart title and the value of A2 as the name of the chart.
Right now, when I look in the VBA editor the macro has recorded the name as
"chart 11" or something like that.
I've tried to use ActiveChart.Name = "James" as the name of the chart, but I
keep getting an error.
Can anyone please help me?
Thanks James
--

  #3   Report Post  
James
 
Posts: n/a
Default

John,
Thanks, you make it look so easy ;-)
James

"John Mansfield" wrote:

James,

Add this code to a standard module. Select the chart and then run the macro
(note: assumes you are referring to an embedded chart on Sheet1 of your
workbook).

Sub ChartMacro()
Dim Cht As Chart
Set Cht = ActiveChart
Cht.Parent.Name = Sheets("Sheet1").Range("A1").Value
Cht.ChartArea.Select
With Cht
.HasTitle = True
.ChartTitle.Characters.Text = Sheets("Sheet1").Range("A2").Value
End With
MsgBox "The chart name is: " & Cht.Parent.Name
MsgBox "The chart title is: " & Cht.ChartTitle.Characters.Text
End Sub

----
Regards,
John Mansfield
http://www.pdbook.com

"James" wrote:

Is there a way to record a macro when creating a chart and use the value of
A1 as the chart title and the value of A2 as the name of the chart.
Right now, when I look in the VBA editor the macro has recorded the name as
"chart 11" or something like that.
I've tried to use ActiveChart.Name = "James" as the name of the chart, but I
keep getting an error.
Can anyone please help me?
Thanks James
--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Macro to Update Chart ddng Charts and Charting in Excel 1 February 18th 05 11:41 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Import chart to Power Point and Macro problem Woody13 Excel Discussion (Misc queries) 1 December 8th 04 05:47 PM
pivot table multi line chart souris Charts and Charting in Excel 2 December 7th 04 03:56 AM


All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"