Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing decimal of y-axis of a chart in vba (Excel (macro))

    How do I change the decimal place of the y-axis in a chart with vba. right now it is at 2 which is the default, but I want it to be 0 where it just shows the whole number


    Thanks Jonathan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Changing decimal of y-axis of a chart in vba (Excel (macro))

    If the chart is currently selected:

    ActiveChart.Axes(xlValue).TickLabels.NumberFormat = "0"

    Otherwise:

    ActiveSheet.ChartObjects(1).Chart.Axes(xlValue).Ti ckLabels.NumberFormat = "0"

    assuming the chart is the first (or only) one on the sheet. If you have already defined a Chart variable cht:

    cht.Axes(xlValue).TickLabels.NumberFormat = "0"

  3. #3
    New Lounger
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing decimal of y-axis of a chart in vba (Excel (macro))

    Thanks
    I tried doing this (cht.Axes(xlDataLabelsShowValue).TickLabels.Number Format = "0") to change the decimal placing of the data labels to 0, but it doesnt work. How would you do that
    Thanks Jonathan

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Changing decimal of y-axis of a chart in vba (Excel (macro))

    Data labels are not the same as axes. You have to set the number format for the data labels for a specific series:

    cht.SeriesCollection(1).DataLabels.NumberFormat = "0"

    or for all series:

    Dim ser As Series
    For Each ser in cht.SeriesCollection
    ser.DataLabels.NumberFormat = "0"
    Next ser

  5. #5
    New Lounger
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing decimal of y-axis of a chart in vba (Excel (macro))

    Thank You

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •