Set Major Unit on Chart using VBA

PJGallagher

New Member
Joined
Jul 8, 2016
Messages
2
Hi all,

Newbie here...

I have a spreadsheet file containing two sheets (Sheet1 & Sheet2).

Sheet2 is populated with some raw data pulled in from a .CSV file daily. The data range grows in size over time, daily stats for my work.

I produce a dashboard (Sheet1) showing 3 different charts that each point to specific data in Sheet2.

The charts auto populate daily (VBA runs when user clicks a button) showing data up to the latest entry in Sheet2.

PROBLEM: The issue is the X Axis on the charts changes from the default of 1 to a large number which seems to relate to the number of rows being referenced. So, the real dates are not displayed on the X Axis, just the first date and no more dates.

If I manually change the chart X Axis Major Unit to 1 (or click reset on the chart formating) the correct dates are shown on X Axis.

QUESTION: How can I set the X Axis Major Unit to 1 month in VBA? I have 3 charts on Sheet1 that I need to make this work for...

Many thanks in advance

Paul G
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi and welcome to the Board

Code:
Sub All_Charts_on_Sheet()
Dim cho As ChartObject
For Each cho In Sheets("sheet3").ChartObjects
    cho.Chart.Axes(xlCategory).MajorUnit = 1
    'cho.Chart.Axes(xlCategory).MajorUnitIsAuto = True
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top