Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Align Chart Axis

Status
Not open for further replies.

DAVEKELLY

Technical User
Apr 15, 2001
11
AU
Using Jon Peltier's example for aligning axes in Excel 2003 - the code correctly calcluates and aligns the left and right axes for me - however in 2007 it returns incorrect values.

If I then run the code in step mode (in 2007) it returns the correct results.

Any suggestions?
Many Thanks
 


and the code is???????

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


Here's some code that works for me in 2007...
Code:
Private Sub Worksheet_Calculate()
    Dim axPRI As Axis
    
    With chNet
        Set axPRI = .Axes(xlValue, xlPrimary)
        With axPRI
            .MaximumScaleIsAuto = True
            .MinimumScaleIsAuto = True
        End With
        
        With .Axes(xlValue, xlSecondary)
            .MaximumScaleIsAuto = True
            .MinimumScaleIsAuto = True
            
            If axPRI.MaximumScale > .MaximumScale Then
                .MaximumScale = axPRI.MaximumScale
            Else
                axPRI.MaximumScale = .MaximumScale
                .MaximumScale = axPRI.MaximumScale
            End If
            
            If axPRI.MinimumScale < .MinimumScale Then
                .MinimumScale = axPRI.MinimumScale
            Else
                axPRI.MinimumScale = .MinimumScale
                .MinimumScale = axPRI.MinimumScale
            End If
        End With
    End With
    Set axPRI = Nothing
End Sub
where chNet is my chart.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks Skip.
I will use and test your code tonight.

The code was from Jon Peltier's graphing site and his code is the only code I received by 'googling' for aligning zero on left and right axes.

Strange that Jon's code returns incorrect min values on run, but in step mode it returns correct values for me. Works OK in 2003 but seems not to in 2007.
Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top