ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Chart title: Text and Formula together? VBA (https://www.excelbanter.com/excel-programming/446965-chart-title-text-formula-together-vba.html)

KeriM

Chart title: Text and Formula together? VBA
 
I'm trying to use Excel VBA to autocreate a chart title based on a cell value. This is what I've got so far:

Code:

.ChartTitle.Text = "Progress (as of " & "='OtherSheet'!R6C7" & ")"
It's supposed to say (as an example): Progress (as of August 28,2012)

The "August 28, 2012" is written in a cell in another sheet. I've tried double quotes, I've tried putting the = before the text and in the formula. The above code results everything written out as text, including the formula. It is just listing the formula as text, and it's not actually getting the value of that cell. Does anyone know the correct syntax to get this to work?

KeriM

Quote:

Originally Posted by KeriM (Post 1605015)
I'm trying to use Excel VBA to autocreate a chart title based on a cell value. This is what I've got so far:

Code:

.ChartTitle.Text = "Progress (as of " & "='OtherSheet'!R6C7" & ")"
It's supposed to say (as an example): Progress (as of August 28,2012)

The "August 28, 2012" is written in a cell in another sheet. I've tried double quotes, I've tried putting the = before the text and in the formula. The above code results everything written out as text, including the formula. It is just listing the formula as text, and it's not actually getting the value of that cell. Does anyone know the correct syntax to get this to work?

Once again, I found a workaround; however, if someone knows how to get this working, I'm curious to know. I ended up just putting everything in another cell and then referring to that cell in my VBA.

Don Guillett[_2_]

Chart title: Text and Formula together? VBA
 
On Tuesday, August 28, 2012 11:10:03 AM UTC-5, KeriM wrote:
I'm trying to use Excel VBA to autocreate a chart title based on a cell

value. This is what I've got so far:





Code:

--------------------



.ChartTitle.Text = "Progress (as of " & "='OtherSheet'!R6C7" & ")"



--------------------





It's supposed to say (as an example): Progress (as of August 28,2012)



The "August 28, 2012" is written in a cell in another sheet. I've tried

double quotes, I've tried putting the = before the text and in the

formula. The above code results everything written out as text,

including the formula. It is just listing the formula as text, and it's

not actually getting the value of that cell. Does anyone know the

correct syntax to get this to work?









--

KeriM


Try this
Sub charttitlesas()
With ActiveSheet.ChartObjects("Chart 2").Chart
..HasTitle = True
..charttitle.Characters.Text = "My Date is " & _ sheets("sheet10").Range("e1")
End With
End Sub

KeriM

Quote:

Originally Posted by Don Guillett[_2_] (Post 1605033)
On Tuesday, August 28, 2012 11:10:03 AM UTC-5, KeriM wrote:
I'm trying to use Excel VBA to autocreate a chart title based on a cell

value. This is what I've got so far:





Code:

--------------------



.ChartTitle.Text = "Progress (as of " & "='OtherSheet'!R6C7" & ")"



--------------------





It's supposed to say (as an example): Progress (as of August 28,2012)



The "August 28, 2012" is written in a cell in another sheet. I've tried

double quotes, I've tried putting the = before the text and in the

formula. The above code results everything written out as text,

including the formula. It is just listing the formula as text, and it's

not actually getting the value of that cell. Does anyone know the

correct syntax to get this to work?









--

KeriM


Try this
Sub charttitlesas()
With ActiveSheet.ChartObjects("Chart 2").Chart
..HasTitle = True
..charttitle.Characters.Text = "My Date is " & _ sheets("sheet10").Range("e1")
End With
End Sub

That works! Thank you!


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com