+ Reply to Thread
Results 1 to 7 of 7

Automatic change in axis scale

  1. #1
    Registered User
    Join Date
    02-25-2016
    Location
    Los Angeles
    MS-Off Ver
    2013
    Posts
    4

    Automatic change in axis scale

    Hello Excelforum members,

    I'm a beginner to VBA and was hoping to get assistance on how to change the Y-axis when values change. In the attached file, if I change cell C28, the graph automatically changes. But, using VBA, how do I change the Y-axis? For example, when I change the dropdown to Team C, I would like the Y-axis to start at 40, rather than zero.

    Any help would be greatly appreciated.
    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Automatic change in axis scale

    This should teach you everything you need to know: http://peltiertech.com/link-excel-ch...lues-in-cells/
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    02-25-2016
    Location
    Los Angeles
    MS-Off Ver
    2013
    Posts
    4

    Re: Automatic change in axis scale

    Thank you MrShorty. That worked perfectly, although I am now running into another issue.

    I assigned a macro to the Click Me button in the attached file so the macro can run after I select the dropdown to a different team. But, I received a Run-time error '91' Object variable or With block variable not set. But, when I run the Macro from the Developer tab, it works. Any thoughts?
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Automatic change in axis scale

    When I click on "debug", it highlights the "ActiveChart" with statement. This suggests to me that it is not recognizing what "activechart" is. I would suggest that you assume that the chart is not "active" and designate the chart in a less ambiguous way. Can I assume you are familiar with the Excel object model, so that you can find your through the hierarchy of objects and collections to designate a chart? If needed, you might review the Excel object model: https://msdn.microsoft.com/en-us/lib.../ff194068.aspx In particular, look at the ChartObjects object/collection.

  5. #5
    Registered User
    Join Date
    02-25-2016
    Location
    Los Angeles
    MS-Off Ver
    2013
    Posts
    4

    Re: Automatic change in axis scale

    Thank you for your reply MrShorty. I'm afraid I am not familiar with Excel object model. I'm a beginner to VBA. I see that the error is with "ActiveChart". What do you mean I need to designate the chart in a less ambiguous way?

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Automatic change in axis scale

    Start with its parent object, then work through the objects and collections. As I suggested, in particular, you will want to be familiar with the chartobjects() collection. If you did not follow the link to the chartobjects object and look at the examples there, then I strongly encourage you to do so. Recognize that VBA is an "object oriented" language, so understanding the Object model is a very important part of learning the programming language and learning how to interact with Excel.

    Perhaps Activesheet will be reliable enough (ActiveSheet.ChartObjects(1).Chart.Axes.....)
    When I need something absolutely unambiguous, I will often use the ThisWorkbook object (Thisworkbook.sheets(...).chartobjects(...).etc.

  7. #7
    Registered User
    Join Date
    02-25-2016
    Location
    Los Angeles
    MS-Off Ver
    2013
    Posts
    4

    Re: Automatic change in axis scale

    Activesheet worked. Thank you MrShorty!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Change x axis scale mid graph on timeline
    By natedawg400 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-22-2011, 08:54 AM
  2. How do I change the scale on the x axis?
    By Simonha in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 12-20-2009, 01:03 AM
  3. Change scale on dual x axis
    By mandrews in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-09-2007, 07:22 PM
  4. Can't change the scale of values on a y-axis on a line chart
    By ags in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-07-2006, 07:40 PM
  5. [SOLVED] how do i change the x-axis of a graph to a log scale?
    By anne in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-13-2006, 02:35 PM
  6. [SOLVED] How do I change the scale of logrithmic curve on the x-axis?
    By les in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 09-08-2005, 02:05 PM
  7. [SOLVED] How do I change the scale of the catagory axis?
    By amcmaster in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 03-02-2005, 01:06 PM
  8. Change the value axis scale
    By SJ in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-24-2005, 04:06 PM

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