Trying to use a cell reference value in X Axis value of Chart

Ronanm

Board Regular
Joined
Nov 13, 2010
Messages
107
Hi

I'm trying to use a cell reference value in the X Axis labels of Chart.
For example the static axis labels reference would be
=Student!$B$26:$R$26

However instead of it being $B$26, I need it to be $B with whatever Row number my named range "ColumnNumber" returns.

Many thanks

Ronan
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I set up a named range on Sheet1 for cells or range D4:D8 -- named "ColumnNumber"
then in the immediate window, I entered:

? Activesheet.Range("ColumnNumber").row
4 << The first row of the named range "ColumnNumber"
 
Upvote 0
Use the OFFSET function in a defined name, like =OFFSET(Student!$B$1,ColumnNumber-1,0,1,17), and reference the defined name in the axis labels reference as =SheetName!DefName.
 
Upvote 0
Short sample... maybe helpful....

Code:
Sub Macro1()
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.SeriesCollection(1).Select
    RNum = Range("ColumnNumber").Row
    ActiveChart.SeriesCollection(1).Formula = _
        "=SERIES(,Student!$C$" & RNum & ":$C$10,Student!$D$" & RNum & ":$D$10,1)"
End Sub
 
Upvote 0
Mmmn thanks. Sorry, I made a slight error :mad:

If my ColumnNumber named range returns 12, I need the Axis Labels to be P26:R26 instead of B26:R26. Which would show Years (labels) from 2007 to 2010, instead of 1994 to 2010.

Obviously in my Charts X Axis I can't simply have
=Students!$ColumnNumber$26:$R$26 which is a shame...

Many thanks

Ronan
 
Upvote 0
Mmmn. Many thanks, but ideally would like to steer clear of code... Life is difficult enough as it is :o)
 
Upvote 0
Mmmn thanks. Sorry, I made a slight error :mad:

If my ColumnNumber named range returns 12, I need the Axis Labels to be P26:R26 instead of B26:R26. Which would show Years (labels) from 2007 to 2010, instead of 1994 to 2010.

Obviously in my Charts X Axis I can't simply have
=Students!$ColumnNumber$26:$R$26 which is a shame...

Many thanks

Ronan
=OFFSET(Student!$B$1,0,ColumnNumber+2,1,ColumnNumber-9)
 
Upvote 0
Hi Thanks for the input.
I have made my changes (tried to attach a sample file, but couldn't so went to http://www.excelforum.com)

Two issues...
One is the the labels always appear at the start of the X axis, so I end up with 2008, 2009, 2010 at the start, but the columns of data at the end...
Secondly is that ideally I would like the Chart to expand and contract (which would also fix the first problem), so that if there were only 3 years, then it would only be 3 Years wide...

Many thanks

Ronan
 
Upvote 0
You have to adjust all your data to match the labels. Use OFFSETs for all of it.
 
Upvote 0

Forum statistics

Threads
1,223,520
Messages
6,172,811
Members
452,481
Latest member
Najwan

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