ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   XL2002 - Setting same MaxValue on 2 axes... (https://www.excelbanter.com/excel-programming/388464-xl2002-setting-same-maxvalue-2-axes.html)

Trevor Williams

XL2002 - Setting same MaxValue on 2 axes...
 
I have a chart with 2 axes (one for columns, one for lines). I need to set
the Maximum values on both axes to be the same, BUT if at all possible, I'd
like Excel to automatically choose the Maximum Value of either axis and then
apply that value to the other axis. i.e. If the primary axis is automatically
set at 100 and the secondary axis is automatically set at 500, I need to
reset the primary axis to 500.

Thanks in Advance

Trevor Williams

Peter T

XL2002 - Setting same MaxValue on 2 axes...
 
Hi Trevor,

One way -

Sub test()
Dim axs As Axes
Dim mx1, mx2
Set axs = ActiveSheet.ChartObjects(1).Chart.Axes ' Change to relevant chart

mx1 = axs(xlValue, xlPrimary).MaximumScale
mx2 = axs(xlValue, xlSecondary).MaximumScale

If mx1 mx2 Then
axs(xlValue, xlSecondary).MaximumScale = mx1
ElseIf mx2 mx1 Then
axs(xlValue, xlPrimary).MaximumScale = mx2
End If

End Sub

Or maybe monitor the maximum point value in all series.

You might also want to recheck in a change event or, if the data is returned
by cell formulas the calculate event (events of the sheet containing the
data). Include an error handler.

Regards,
Peter T

"Trevor Williams" wrote in
message ...
I have a chart with 2 axes (one for columns, one for lines). I need to

set
the Maximum values on both axes to be the same, BUT if at all possible,

I'd
like Excel to automatically choose the Maximum Value of either axis and

then
apply that value to the other axis. i.e. If the primary axis is

automatically
set at 100 and the secondary axis is automatically set at 500, I need to
reset the primary axis to 500.

Thanks in Advance

Trevor Williams




Trevor Williams

XL2002 - Setting same MaxValue on 2 axes...
 
Hi Peter - Thanks very much for this, it works a treat!

Trevor

"Peter T" wrote:

Hi Trevor,

One way -

Sub test()
Dim axs As Axes
Dim mx1, mx2
Set axs = ActiveSheet.ChartObjects(1).Chart.Axes ' Change to relevant chart

mx1 = axs(xlValue, xlPrimary).MaximumScale
mx2 = axs(xlValue, xlSecondary).MaximumScale

If mx1 mx2 Then
axs(xlValue, xlSecondary).MaximumScale = mx1
ElseIf mx2 mx1 Then
axs(xlValue, xlPrimary).MaximumScale = mx2
End If

End Sub

Or maybe monitor the maximum point value in all series.

You might also want to recheck in a change event or, if the data is returned
by cell formulas the calculate event (events of the sheet containing the
data). Include an error handler.

Regards,
Peter T

"Trevor Williams" wrote in
message ...
I have a chart with 2 axes (one for columns, one for lines). I need to

set
the Maximum values on both axes to be the same, BUT if at all possible,

I'd
like Excel to automatically choose the Maximum Value of either axis and

then
apply that value to the other axis. i.e. If the primary axis is

automatically
set at 100 and the secondary axis is automatically set at 500, I need to
reset the primary axis to 500.

Thanks in Advance

Trevor Williams






All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com