Matching Primary and Secondary Axis

Jono_NZ

Board Regular
Joined
Sep 4, 2007
Messages
75
Hi,

I have a number of charts where I need to automatically ensure the secondary axis scale matches the primary axis.

I'm pretty sure I'll need to use VBA for this. Does anyone know how to help?

Thanks in advance!
 

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.

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi Jono,

A simple macro can do this. You can either write the macro to check the selected chart, or do all the charts on a particular sheet, or process all the charts in the workbook.

You didn't mention what you definition of "matching" is. It could be axis length, min and max value, axis label text and formatting, tick placement and formatting, grid lines, number formatting, etc. Do you want all of these to match?

Damon
 
Upvote 0

Jono_NZ

Board Regular
Joined
Sep 4, 2007
Messages
75
Hi Jono,

A simple macro can do this. You can either write the macro to check the selected chart, or do all the charts on a particular sheet, or process all the charts in the workbook.

You didn't mention what you definition of "matching" is. It could be axis length, min and max value, axis label text and formatting, tick placement and formatting, grid lines, number formatting, etc. Do you want all of these to match?

Damon


Damon,

Just the min and max values.
 
Upvote 0

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi again Jono,

Okay, here is a macro that operates on the currently selected chart object.

Code:
Sub MakeYaxisSameAsXaxis()
   'makes the chart Value value axis (y-axis) max and min
   'scale values the same as the category (x-axis) max and min
   'values.  Operates on the currently selected chart. Note: to
   'manually select the chart, ctrl-click on the chart.
   With Selection.Chart
      .Axes(xlValue).MinimumScale = .Axes(xlCategory).MinimumScale
      .Axes(xlValue).MaximumScale = .Axes(xlCategory).MaximumScale
   End With
End Sub

Important note: to select the chart object you must Ctrl-Click on the chart.

I hope you find this helpful.

Damon
 
Upvote 0

Forum statistics

Threads
1,195,938
Messages
6,012,416
Members
441,698
Latest member
DaveTeo

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