+ Reply to Thread
Results 1 to 2 of 2

Set Secondary Axis with VBA

  1. #1
    Registered User
    Join Date
    04-19-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    3

    Question Set Secondary Axis with VBA

    Hello,

    I'm trying to write a macro to reset the primary and Secondary Y axes of all charts contained in one sheet.
    The code below works fine for primary but I'm getting a run time error for the secondary.
    I thought it could be because only one third of the charts have a secondary axis, so I tried to insert an if condition to test its existence (via existence of title, which isn't really the same...) but this doesn't help.
    Any help would be much appreciated.
    Thanks.
    Julien

    Sub ChangeScale()
    For Each ChtObj In Sheet3.ChartObjects 'Only look at specified sheet
    With ChtObj.Chart
    With .Axes(xlValue)
    .MaximumScale = ActiveSheet.Range("D1").Value
    .MinimumScale = ActiveSheet.Range("C1").Value
    .MajorUnit = ActiveSheet.Range("E1").Value
    End With
    If .Axes(xlValue, xlSecondary).HasTitle = True Then
    With .Axes(xlValue, xlSecondary) 'or: With .Axes(2, 2)
    .Select '??????
    .MaximumScale = ActiveSheet.Range("D2").Value
    .MinimumScale = ActiveSheet.Range("C2").Value
    .MajorUnit = ActiveSheet.Range("E2").Value
    End With
    End If
    End With
    Next
    End Sub

  2. #2
    Registered User
    Join Date
    04-19-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Set Secondary Axis with VBA

    Could anybody assist ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1