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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

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