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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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
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
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,224,315
Messages
6,177,842
Members
452,809
Latest member
mar_luna

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