?
Solved

Excel 2003 VBA - changing axis scale upon worksheet change

Posted on 2013-02-04
3
Medium Priority
?
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

752 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