[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Excel 2003 VBA - changing axis scale upon worksheet change

Posted on 2013-02-04
3
Medium Priority
?
467 Views
Last Modified: 2013-02-11
Worksheet with combo boxes. User selects combos linked to a cell and the chart changes according to selections. Need the axis to also adjust to my named ranges.  I would like this to be upon a worksheet_change vs manually calling the macro/code if possible.

I've tried many different ways of doing this and have nothing workable yet. I need this asap and have spent many many hours researching this from examples.


Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ch As ChartObject
    Set ch = Worksheets(Summary).ChartObjects("Chart 16").Select
 
    With ch.Axes(xlValue, xlSecondary)
        .MinimumScale = ActiveSheet.Name("MinScale_LP")
        .MaximumScale = ActiveSheet.Name("MaxScale_LP")
    End With
   
    With ch.Axes(xlValue, xlSecondary)
        .MinimumScale = Summary.Name("MinScale_GFWC")
        .MaximumScale = Summary.Name("MaxScale_GFWC")
    End With
End Sub

This did not work either:
Private Sub Worksheet_Change(ByVal Target As Range)

    ActiveSheet.ChartObjects("Chart 16").Chart.Axes(xlValue).MaximumScale = MaxScale_LP
    ActiveSheet.ChartObjects("Chart 16").Chart.Axes(xlValue).MinimumScale = MinScale_LP
    ActiveSheet.ChartObjects("Chart 16").Chart.Axes(xlValue, xlSecondary).MaximumScale = MaxScale_GFWC
    ActiveSheet.ChartObjects("Chart 16").Chart.Axes(xlValue, xlSecondary).MinimumScale = MinScale_GFWC

End Sub
0
Comment
Question by:culpees
  • 2
3 Comments
 

Accepted Solution

by:
culpees earned 0 total points
ID: 38853523
Nevermind. I figured it out.
I recorded a macro to see what Excel wrote for the code and came up with this:
Private Sub Worksheet_Change(ByVal Target As Range)

    ActiveSheet.ChartObjects("Chart 16").Activate
    ActiveChart.Axes(xlValue).Select
    With ActiveChart.Axes(xlValue)
        .MinimumScale = Range("$Q$32")
        .MaximumScale = Range("$r$32")
        .MajorUnitIsAuto = True
        .MajorUnit = Range("$S$32")
        .MinorUnitIsAuto = Range("$T$32")
        .MinorUnit = Range("$u$32")
    End With
    ActiveChart.Axes(xlValue, xlSecondary).Select
    With ActiveChart.Axes(xlValue, xlSecondary)
        .MinimumScale = Range("$Q$33")
        .MaximumScale = Range("$r$33")
        .MajorUnitIsAuto = True
        .MajorUnit = Range("$S$33")
        .MinorUnitIsAuto = Range("$T$33")
        .MinorUnit = Range("$u$33")
    End With
End Sub

It wasn't working with defined names, so I had to use ranges.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 38858560
FYI, it should work with named ranges too if you use
Range("MaxScale_LP")
syntax.
0
 

Author Closing Comment

by:culpees
ID: 38875398
I resolved it before anyone else bothered to answer.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question