Properties of the Axis class

tcmsklas

New Member
Joined
May 11, 2017
Messages
2
I want to use programatic adjusting of a chart in Excel 2016. I found a list of properties belonging to the Axis class here -> Excel class Axis VBA.
I can set the CategoryType to xlTimeScale programmatically using VBA, but I get a runtime error when I try to set the MajorUnitScale.

How can I control these properties from VBA?

Here is the code I am using:

Public Sub Fix_chart()

Dim ws As Worksheet
Dim ch As ChartObject
Dim xA As Object
Dim yA As Object

Set ws = Sheets("Sheet1")
Set ch = ws.ChartObjects(1)

ch.Chart.HasTitle = True
ch.Chart.ChartTitle.Text = "Temperatur"

Set xA = ch.Chart.Axes(xlCategory)
Set yA = ch.Chart.Axes(xlValue)

yA.MinimumScale = 15
yA.MaximumScale = 35

xA.MinimumScale = Hour(Now()) / 24
xA.MaximumScale = (Hour(Now()) + 2) / 24
xA.CategoryType = xlTimeScale
xA.MajorUnitScale = 1 / 24 'corresponding to one hour, gives runtime error "Property not used by value axes"


End Sub
 

Attachments

  • 1661698775568.png
    1661698775568.png
    18.8 KB · Views: 3

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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