Changing chart axis title based on text in a cell
Hello, i'm fairly new to excel vba. I'm using excel 2010 and trying to change the label on the x axis of a chart based on text entered into a cell. Below is some of the code I have pieced together, but there is an error when I try to run the code:
Sub ChangeAxisTitle()
'X-Axis Title
Dim xaxis As axis
With ActiveChart
range("P37") = .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text
With .Axes(xlCategory)
.HasTitle = True
If ActiveSheet.range("$M$37").Text = "Title 1" Then
.AxisTitle.Characters.Text = "Time"
Else: .AxisTitle.Characters.Text = "Title 2"
End If
End With
End With
End Sub
|