Using a string to make a sheet reference question

cfdh_edmundo

Board Regular
Joined
Nov 9, 2005
Messages
133
Hi,

I'm trying to perform a sheet reference (for an axis on a chart) in VBA but it seems to keep going wrong.

When I hard-code the sheet path in it works, e.g.

Rich (BB code):
ActiveChart.SeriesCollection(1).XValues = "='01.12.09'!R4C1:R45C1"

This picks up the range A4:A45 from the sheet named 01.12.09 and uses it as the x axis values.


However when I try and make this more dynamic, by replacing the 01.12.09 with a string which has the sheet name (dateLookingAt is used to generate the name of the sheet) it seems to have problems:

Rich (BB code):
ActiveChart.SeriesCollection(1).XValues = ""=dateLookingAt&"!R4C1:R45C1"


I think I've messed up the "" and/or ''. Does anyone know how to solve this?

Many thanks,

Chris
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,881
Hi Chris

Try:

Code:
ActiveChart.SeriesCollection(1).XValues = "='" & dateLookingAt & "'!R4C1:R45C1"
 

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,651
Members
414,083
Latest member
Mrsash

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
Top