![use secondary axis in excel for mac use secondary axis in excel for mac](https://d13ot9o61jdzpp.cloudfront.net/images/secondary_axis_3.png)
- Use secondary axis in excel for mac how to#
- Use secondary axis in excel for mac code#
- Use secondary axis in excel for mac series#
SYmax = ch.Axes(xlValue, xlSecondary).MaximumScale 'Get the maximum bound of the secondary Y axis. SYmin = ch.Axes(xlValue, xlSecondary).MinimumScale 'Get the mininmum bound of the secondary Y axis. 'Calculate the number of major gridlines. 'Get the major unit of the primary Y axis. 'Get the maximum bound of the primary Y axis. 'Get the mininmum bound of the primary Y axis. Axes(xlValue, xlSecondary).MajorUnitIsAuto = True Axes(xlValue, xlSecondary).MaximumScaleIsAuto = True Axes(xlValue, xlSecondary).MinimumScaleIsAuto = True 'For the primary Y axis this is NOT always necessary, so the corresponding 3 lines can be deleted/commented. 'Set the minimum/maximum bound and the major unit to Auto for both primary and secondary axes. MsgBox "The chart wasn't set!", vbCritical, "Empty Chart" 'A quick test if the ch variable is not empty. 'If you need to set the ch variable to active chart you can use the next line: 'Set the ch variable to a specific chart on sheet 1 (in this example). 'primary and secondary Y axes share the same number of (major) gridlines. 'Automatically adjusts the scale of the secondary Y axis, so that both It’s a short macro that can be customized according to your needs.
Use secondary axis in excel for mac code#
VBA code for adjusting the secondary Y-axisĪnd here is the “easy way” no need to test the values on the text boxes, no worries about how the axes will look uniformly. In the last step, you might need to make some (repeating) tests on the values that you will enter in the 3 text boxes (especially in the Major Unit text box) in order to achieve that both primary and secondary axes will share the same number of gridlines.
Use secondary axis in excel for mac series#
![use secondary axis in excel for mac use secondary axis in excel for mac](https://blog.hubspot.com/hs-fs/hubfs/change-chart-type.png)
![use secondary axis in excel for mac use secondary axis in excel for mac](http://2.bp.blogspot.com/-6KFvI4dMPww/VI1ZGvuACmI/AAAAAAAAAUA/AHe0xen5QUI/s1600/secondary_chart26.jpg)
![use secondary axis in excel for mac use secondary axis in excel for mac](http://www.agentjim.com/MVP/Excel/HistoColDone2016.png)
Just follow the instructions that follow (for Excel 2013). So, I found the code that I had written then (2012) and I made some minor changes in order to make it more generic, and, here it is!īy the way, it’s not hard to adjust the scale of the secondary Y axis manually. Second, the question reminded me of a similar need that I had some years ago. In the COPERT Micro tool, for example, I have many charts that show emissions (primary Y) and the number of vehicles (secondary Y) as a function of the hour of the day (X-axis). I thought this question was interesting for two reasons: first, it’s quite common to include a secondary Y-axis on a chart, just to display another series that has a different scale than the first one.
Use secondary axis in excel for mac how to#
The question was “ how to automatically set the secondary Y axis scale via code so that both primary and secondary axes share the same number of gridlines”. Some days ago, while I was checking the discussions on an Excel-related group on LinkedIn, I bumped into an interesting question about charts.