Unhandled Exception
Unhandled Exception

Reputation: 1513

Excel VBA and Charts. Y Axis label issue

Just starting out with Excel and Charts....

Current code :

With excel_Chart.Chart
    .ChartType = xlColumnClustered
    .SeriesCollection.NewSeries
    .SeriesCollection(1).Values = _
            Array(numOfSmallHits, numOfAllHits, numOfTallHits)  'array_value
End With

Generates these two charts. When both values are 1, the Y-Axis shows 0, 0.5, 1, 1.5

enter image description here

enter image description here

When one value is 1 and the other is 2, the Y-Axis shows 0, 1, 2, 3

I don't want to use hard-coded labels as this is a dynamic chart but I do want to use whole numbers only. My attempt to do so was by adding the following line of code to the above snippet.

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

At first it appears nothing has changes when the values are 1 & 2.

enter image description here

But when both values happen to be 1, then I get a duplicate value on the Y-Axis (0,1,1,2).

enter image description here

For a dynamic chart, what property needs to be set in order to only have whole numbers appear in increments of 1. For example, 0,1,2,3,4,5....

Upvotes: 0

Views: 427

Answers (1)

BigBen
BigBen

Reputation: 49998

I think you're looking for the Axis.MajorUnit property.

Try:

.Axes(xlValue).MajorUnit = 1

Upvotes: 2

Related Questions