+ Reply to Thread
Results 1 to 4 of 4

Vba to set line chart Yaxis Max, Min, Major Unit

  1. #1
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Vba to set line chart Yaxis Max, Min, Major Unit

    I am trying to use vba to set the Yaxis Max, Min and Major Units for a dynamic line chart. The chart changes based on user selections from a data validation cell.
    I am using this code

    ActiveSheet.ChartObjects("Chart 3").Activate
    With ActiveChart.Axis(xlValue)
    .TickLabels.AutoScaleFont = False
    .MaximumScale = Sheets("Compile").Range("AI25").Value
    .MinimumScale = Sheets("Compile").Range("AI24").Value
    .MajorUnit = Sheets("Compile").Range("AI26").Value
    End With

    But when I run it the plot area moves around inside the chart area and the chart area resizes.
    After looking around for a solution, I tried “locking” the axis font autoscale like this.
    .TickLabels.AutoScaleFont = False

    This caused everything to move around but didn’t really fix the problem.
    So I tried setting values for the Chart and plot areas like this…
    With ChartArea
    .Left = 740
    .Width = 330
    .Top = 140
    .Height = 210
    End With
    With PlotArea
    .Left = 0
    ' .Width = 335
    .Top = 5
    ' .Height = 220
    End With

    But it doesn’t fix the issue.

    All I want to do is set the Yaxis Max, Min and Major unit based on a calculation I am doing on the data. But when I apply it, it seems to change a lot of other settings on the chart. The more things I try to fix it, The more confused I get about what’s helping and what’s hurting. Anyone have any insight on this issue?

    Thanks

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,665

    Re: Vba to set line chart Yaxis Max, Min, Major Unit

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: Vba to set line chart Yaxis Max, Min, Major Unit

    I am trying to use vba to set the Yaxis Max, Min and Major Units for a dynamic line chart. The chart changes based on user selections from a data validation cell.
    I am using this code

    Please Login or Register  to view this content.
    But when I run it the plot area moves around inside the chart area and the chart area resizes.
    After looking around for a solution, I tried “locking” the axis font autoscale like this.
    Please Login or Register  to view this content.
    This caused everything to move around but didn’t really fix the problem.
    So I tried setting values for the Chart and plot areas like this…
    Please Login or Register  to view this content.
    But it doesn’t fix the issue.

    All I want to do is set the Yaxis Max, Min and Major unit based on a calculation I am doing on the data. But when I apply it, it seems to change a lot of other settings on the chart. The more things I try to fix it, The more confused I get about what’s helping and what’s hurting. Anyone have any insight on this issue?

    Thanks

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,665

    Re: Vba to set line chart Yaxis Max, Min, Major Unit

    You didn't attach a workbook, so I experimented with an old one, adjusting the Y (i.e. value) axis:
    Please Login or Register  to view this content.

+ 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. How does Excel Determine Major Unit and can it be controlled
    By dgardineer in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 10-25-2013, 05:50 AM
  2. [SOLVED] Formulas to determine max value,Major Unit and min value of chart ?
    By begilhang in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 03-06-2013, 03:39 PM
  3. Setting Major Unit in Chart- can they be set individually
    By ExcelFed in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 12-04-2008, 02:51 PM
  4. Major scale unit must be integer
    By nsv in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 02-22-2008, 04:42 AM
  5. [SOLVED] Changing the scale major unit in a graph
    By Ant in forum Excel General
    Replies: 2
    Last Post: 02-06-2006, 09:45 AM

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