Solved

Excel 2003 VBA - changing axis scale upon worksheet change

Posted on 2013-02-04
3
395 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sum Based On Criteriya 7 19
Tags from access to excel 3 28
Filling Blank Cells 14 17
remove lower case characters in excel formula 12 28
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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 …

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now