+ Reply to Thread
Results 1 to 6 of 6

Adjusting chart Y-axis value using VBA

Hybrid View

goels Adjusting chart Y-axis value... 11-07-2011, 06:49 AM
Andy Pope Re: Adjusting chart Y-axis... 11-07-2011, 06:58 AM
goels Re: Adjusting chart Y-axis... 11-07-2011, 07:35 AM
Andy Pope Re: Adjusting chart Y-axis... 11-07-2011, 07:37 AM
goels Re: Adjusting chart Y-axis... 11-07-2011, 07:41 AM
goels Re: Adjusting chart Y-axis... 11-07-2011, 08:04 AM
  1. #1
    Registered User
    Join Date
    10-31-2010
    Location
    London
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    56

    Adjusting chart Y-axis value using VBA

    Hi All,

    I have a chart whose minimum value I would like to adjust based on the minimum value in a named range. So for eg if my named range is called Average_weight and if the minimum value of this named range is 40 then I would like the chart's Y-axis to have a minimum value of 40.

    How could I achieve this? Also I would like it to be done such that the minimum value is a rounded down figure i.e. if the minimum value of the named range comes to be 38.76 the minimum value of the Y-axis should be 30. If the minimum value comes to be 22.3 the minimum value of the Y-axis should be 20. This would let me maintain intervals of 10 on my Y-axis.

    Many Thanks
    Last edited by goels; 11-07-2011 at 08:05 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Adjusting chart Y-axis value using VBA

    This example uses a UDF to set scale values.
    http://peltiertech.com/Excel/Charts/...nkToSheet.html

    You can use the FLOOR formula to calculate the new min value to use.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    10-31-2010
    Location
    London
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    56

    Re: Adjusting chart Y-axis value using VBA

    Thanks Andy.

    I have managed to get it working but one improvement remains. Currently the value is coming from the same worksheet as the one on which the chart is. But I want to place the value on another worksheet and then access it in the code from there. How do I change the 4th line to do this. So for eg if the worksheet I want to place the value in is called 'Weight' how do I call it in the 5th line?

    Thanks

    AlignY ThisWorkbook.Worksheets("Report").ChartObjects("Chart 75").Chart


    Sub AlignY(Cht As Chart)


    With Cht
    With .Axes(xlValue, xlPrimary)
    .MinimumScale = ActiveSheet.Range("Y548").Value
    .MaximumScale = 1
    End With


    End With
    End Sub

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Adjusting chart Y-axis value using VBA

    Just reference the worksheet rather than the activesheet

    .MinimumScale = Worksheets("Weight").Range("Y548").Value

  5. #5
    Registered User
    Join Date
    10-31-2010
    Location
    London
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    56

    Re: Adjusting chart Y-axis value using VBA

    Star! - thank you very much.

  6. #6
    Registered User
    Join Date
    10-31-2010
    Location
    London
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    56

    Re: Adjusting chart Y-axis value using VBA

    Thanks Andy.

    I have managed to get it working but one improvement remains. Currently the value is coming from the same worksheet as the one on which the chart is. But I want to place the value on another worksheet and then access it in the code from there. How do I change the 4th line to do this. So for eg if the worksheet I want to place the value in is called 'Weight' how do I call it in the 4th line?

    Thanks

    AlignY ThisWorkbook.Worksheets("Report").ChartObjects("Chart 75").Chart


    Sub AlignY(Cht As Chart)


    With Cht
    With .Axes(xlValue, xlPrimary)
    .MinimumScale = ActiveSheet.Range("Y548").Value
    .MaximumScale = 1
    End With


    End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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