Changing chart axis names with VB based on a value in a cell?

APechaitis

New Member
Joined
Jun 4, 2008
Messages
6
I am trying to format a chart in excel using VB. I would like to be able to format the axes of the chart based on a cell value -- the X-axis value is in cell "chart1info!$B$4" and the Y-axis value is in "chart1info!$C$4" for instance.

I tried recording a macro for formatting the axes and got this:

With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "FI vs Sparkle"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "FI"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "sparkle"


Is there a way to update the axis to reflect the values in these cells? Any help would be appreciated. Also, any general pointers toward other threads involving VB and charting in excel would be helpful.

FYI, I am currently using Excel 2000 at home, and Excel 2003 at work, I would like the solution to work in both systems, if possible.

Thank you
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Use the (untested)
Code:
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = worksheets("chart1info").range("$B$4").value
Similarly, set the y axis value.
 
Upvote 0
Thanks! That did exactly what I wanted (at least at work with Excel 2003, and I'm assuming it will at home with Excel 2000).
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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