PDA

View Full Version : [SOLVED] Defining both axes titles for charts



divingdingo
11-28-2007, 04:09 AM
i'm trying to set the axistitle object for my charts where the x axis is "m/s"
and the y "hrs of day". i know how to set one as i've been using the following code:


activechart.Axes(xlValue, xlPrimary).AxisTitle.Text = "m/s"

however not sure how to set the other as when i've used 'record macro' to help figure out the code it doesn't give me the right code!! and just gives the following:


activechart.Axes(xlvalue, xlPrimary).AxisTitle.Text = "hours of day"

which has the effect of turning "m/s" into "hrs of day"

how frustrating!

regards
mark

Andy Pope
11-28-2007, 04:32 AM
This will do the axis titles for 2d charts assuming there is a series on the secondary axis.



Sub x()
With ActiveChart
With .Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Text = "Primary Y axis"
End With
With .Axes(xlCategory, xlPrimary)
.HasTitle = True
.AxisTitle.Text = "Primary X axis"
End With
With .Axes(xlValue, xlSecondary)
.HasTitle = True
.AxisTitle.Text = "Secondary Y axis"
End With
With .Axes(xlCategory, xlSecondary)
.HasTitle = True
.AxisTitle.Text = "Secondary X axis"
End With
End With
End Sub

divingdingo
11-28-2007, 04:58 AM
thanks andy

that works great.

just a small question, is it common practice in writing code to use lots of with/end with statements to cut down on code? i think i've started to notice this in others' code


regards

mark

sabael
09-12-2018, 03:23 PM
Excellent.
Is very useful how to use this code lines to set axis names in excel chart axis from Ms Access.:clap: