+ Reply to Thread
Results 1 to 2 of 2

Changing decimal place of y-axis in chart with vba

  1. #1
    Registered User
    Join Date
    08-14-2006
    Posts
    2

    Changing decimal place of y-axis in chart with vba

    I have a macro that creates charts for alot of people. I cant seem to figure out how to change the decimal placing of the y-axis in vba. Right now it is at 2 decimal places (which is the default) and I dont want it to show any decimal places, just the whole number. Does anyone kow the code that will allow me to do this? The code for my macro is below. Any help would be appreciated.

    Thanks
    Jonathan


    Sub Chart()



    Dim i As Long
    Dim n As Long
    Dim wsh As Worksheet
    Dim cho As ChartObject
    Dim cht As Chart
    Set wsh = Worksheets("Emp Data")
    n = wsh.Range("A65536").End(xlUp).Row
    For i = 2 To n
    Set cho = wsh.ChartObjects.Add(Top:=160 * i - 310, Left:=10, _
    Height:=150, Width:=300)
    Set cht = cho.Chart
    cht.ChartType = xlColumnClustered
    cht.SeriesCollection.Add Source:=wsh.Range("F" & i)
    cht.SeriesCollection.Add Source:=wsh.Range("N" & i)
    cht.SeriesCollection.Add Source:=wsh.Range("P" & i)
    cht.SeriesCollection(1).Name = "taint"
    cht.SeriesCollection(2).Name = "4%"
    cht.SeriesCollection(3).Name = "bump it"
    cht.HasAxis(xlCategory) = False
    cht.ApplyDataLabels (xlDataLabelsShowValue)

    Next i
    End Sub

  2. #2
    Andy Pope
    Guest

    Re: Changing decimal place of y-axis in chart with vba

    The macro record is useful for generating the base syntax for a problem
    like this.

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

    Cheers
    Andy

    jtr9999 wrote:
    > I have a macro that creates charts for alot of people. I cant seem to
    > figure out how to change the decimal placing of the y-axis in vba.
    > Right now it is at 2 decimal places (which is the default) and I dont
    > want it to show any decimal places, just the whole number. Does anyone
    > kow the code that will allow me to do this? The code for my macro is
    > below. Any help would be appreciated.
    >
    > Thanks
    > Jonathan
    >
    >
    > Sub Chart()
    >
    >
    >
    > Dim i As Long
    > Dim n As Long
    > Dim wsh As Worksheet
    > Dim cho As ChartObject
    > Dim cht As Chart
    > Set wsh = Worksheets("Emp Data")
    > n = wsh.Range("A65536").End(xlUp).Row
    > For i = 2 To n
    > Set cho = wsh.ChartObjects.Add(Top:=160 * i - 310, Left:=10, _
    > Height:=150, Width:=300)
    > Set cht = cho.Chart
    > cht.ChartType = xlColumnClustered
    > cht.SeriesCollection.Add Source:=wsh.Range("F" & i)
    > cht.SeriesCollection.Add Source:=wsh.Range("N" & i)
    > cht.SeriesCollection.Add Source:=wsh.Range("P" & i)
    > cht.SeriesCollection(1).Name = "taint"
    > cht.SeriesCollection(2).Name = "4%"
    > cht.SeriesCollection(3).Name = "bump it"
    > cht.HasAxis(xlCategory) = False
    > cht.ApplyDataLabels (xlDataLabelsShowValue)
    >
    > Next i
    > End Sub
    >
    >


    --

    Andy Pope, Microsoft MVP - Excel
    http://www.andypope.info

+ 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