How can I programmatically get the name of the worksheet where the data source of a chart is?

DF10

New Member
Joined
Apr 30, 2012
Messages
12
Hi all,
I want to programmatically add a title to a chart.
The chart is on a chart sheet (what happens when you hit F11), not on the same sheet where the data source is.
The title text is on cell A1 of the worksheet with the datasource.

Now if the data source is on the sheet "data" then this works

Code:
    ActiveChart.HasTitle = True
    ActiveChart.ChartTitle.Text = "=data!A1"
However I do not the sheet name (nor the position in the workbook)

I was hoping something like ActiveChart.GetSourceData exists (as opposed to ActiveChart.SetSourceData).

How can identify the worksheet where the data source of my chart is

something like
Code:
mysheet =  ActiveChart.GetSourceData ...
and then 
ActiveChart.ChartTitle.Text = "=mysheet!A1"

Thanks
DF
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You need to parse out the sheet reference from 1 of the series formula

You can try something like this.

Code:
activechart.charttitle.text = "=" & split(split(activechart.SeriesCollection(1).formula,",")(1),"!")(0) & "!A1"
 
Upvote 0

Forum statistics

Threads
1,216,165
Messages
6,129,235
Members
449,496
Latest member
Patupaiarehe

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