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

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Changing decimal of y-axis of a chart in vba (Excel (macro))

    Author
    Topic
    #434495

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1024489

      If the chart is currently selected:

      ActiveChart.Axes(xlValue).TickLabels.NumberFormat = “0”

      Otherwise:

      ActiveSheet.ChartObjects(1).Chart.Axes(xlValue).TickLabels.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”

      • #1024598

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

        • #1024602

          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

    Viewing 0 reply threads
    Reply To: Changing decimal of y-axis of a chart in vba (Excel (macro))

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: