PC Review


Reply
Thread Tools Rate Thread

Chart Title from Cell in Sheet1?

 
 
Mike M 91107
Guest
Posts: n/a
 
      31st Dec 2008
I am a new VBA programmer so please forgive this simple question.

I am trying to change the Title of a chart to the text in a cell on a
worksheet. This code successfully sets the title of the chart to "Stupidity":

Private Sub Chart_Activate()
Dim strChartName As String
strChartName = "stupidity"
Chart1.HasTitle = True
Chart1.ChartTitle.Text = strChartName

End Sub

I would like to replace "Stupidity" with reference to cell Sheet1!$N$1 but
cannot seem to get it to work without running into syntax errors I do not
understand.

Any help gratefully appreciated.
 
Reply With Quote
 
 
 
 
Mike M 91107
Guest
Posts: n/a
 
      31st Dec 2008
This seems to do it:

Public Sub Chart_Activate()
Dim strChartName As String
strChartName = Worksheets(1).Range("N1").value
Chart1.HasTitle = True
Chart1.ChartTitle.Text = strChartName

End Sub

Thanks.

"Mike M 91107" wrote:

> I am a new VBA programmer so please forgive this simple question.
>
> I am trying to change the Title of a chart to the text in a cell on a
> worksheet. This code successfully sets the title of the chart to "Stupidity":
>
> Private Sub Chart_Activate()
> Dim strChartName As String
> strChartName = "stupidity"
> Chart1.HasTitle = True
> Chart1.ChartTitle.Text = strChartName
>
> End Sub
>
> I would like to replace "Stupidity" with reference to cell Sheet1!$N$1 but
> cannot seem to get it to work without running into syntax errors I do not
> understand.
>
> Any help gratefully appreciated.

 
Reply With Quote
 
Shane Devenshire
Guest
Posts: n/a
 
      1st Jan 2009
Hi,

Of course you can do this by selecting the title and then clicking on the
Formula bar and typing = and then clicking on a cell in the spreadsheet.

--
If this helps, please click the Yes button

Cheers,
Shane Devenshire


"Mike M 91107" wrote:

> This seems to do it:
>
> Public Sub Chart_Activate()
> Dim strChartName As String
> strChartName = Worksheets(1).Range("N1").value
> Chart1.HasTitle = True
> Chart1.ChartTitle.Text = strChartName
>
> End Sub
>
> Thanks.
>
> "Mike M 91107" wrote:
>
> > I am a new VBA programmer so please forgive this simple question.
> >
> > I am trying to change the Title of a chart to the text in a cell on a
> > worksheet. This code successfully sets the title of the chart to "Stupidity":
> >
> > Private Sub Chart_Activate()
> > Dim strChartName As String
> > strChartName = "stupidity"
> > Chart1.HasTitle = True
> > Chart1.ChartTitle.Text = strChartName
> >
> > End Sub
> >
> > I would like to replace "Stupidity" with reference to cell Sheet1!$N$1 but
> > cannot seem to get it to work without running into syntax errors I do not
> > understand.
> >
> > Any help gratefully appreciated.

 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      1st Jan 2009
Hi,

To create a link between cell and title text use,


Chart1.ChartTitle.Text = "='" & worksheets(1).name & "'!" & _
Worksheets(1).Range("N1").address(,,xlr1c1)

Cheers
Andy

Mike M 91107 wrote:
> This seems to do it:
>
> Public Sub Chart_Activate()
> Dim strChartName As String
> strChartName = Worksheets(1).Range("N1").value
> Chart1.HasTitle = True
> Chart1.ChartTitle.Text = strChartName
>
> End Sub
>
> Thanks.
>
> "Mike M 91107" wrote:
>
>
>>I am a new VBA programmer so please forgive this simple question.
>>
>>I am trying to change the Title of a chart to the text in a cell on a
>>worksheet. This code successfully sets the title of the chart to "Stupidity":
>>
>>Private Sub Chart_Activate()
>> Dim strChartName As String
>> strChartName = "stupidity"
>> Chart1.HasTitle = True
>> Chart1.ChartTitle.Text = strChartName
>>
>>End Sub
>>
>>I would like to replace "Stupidity" with reference to cell Sheet1!$N$1 but
>>cannot seem to get it to work without running into syntax errors I do not
>>understand.
>>
>>Any help gratefully appreciated.


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chart Axis Title via cell ref. =?Utf-8?B?anUxZXNoYXJ0?= Microsoft Excel Charting 2 5th Dec 2006 02:13 PM
Can I have a value in a chart title that references a cell? =?Utf-8?B?ZHZlZW5odWlz?= Microsoft Excel Misc 1 28th Jun 2006 06:22 PM
Chart title = cell contects Dkso Microsoft Excel Charting 4 27th Aug 2005 01:57 PM
Chart title from a cell Andrew Microsoft Excel Discussion 3 30th Nov 2004 02:48 AM
Cell contents as Chart Title Stephen Pain Microsoft Excel Misc 1 8th Nov 2004 04:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:42 PM.