1

I keep getting run time error 424 when running my VBA code.

this line of my code gets highlighted.

ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Angular Rate (deg/s)"

This is my second chart on the excel so I think VBA is struggling to pick the right chart, I'm just guessing here.

Any thoughts on how to deal with this would be appreciated. Thank you

Mazen
  • 3
  • 3
  • You can specify it by name - for example: `Activesheet.Chartobjects("chart name here").Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Angular Rate (deg/s)"` – Rory Feb 16 '21 at 11:12
  • `"This is my second chart on the excel so I think VBA is struggling to pick the right chart, I'm just guessing here."` A word of advice from the scarred ... I always try to avoid `ActiveSheet`, `ActiveChart`, etc as they rely on a sheet to be visible for the code to (a) work without breaking (b) reliably do what you want it to so always try to set a variable pointing to the object you are manipulating for avoidance of any doubt ... Just IMHO, oh and always `option explicit` oh and always fully qualified range names ... apols if teaching GMa to suck eggs ... – JohnnieL Feb 16 '21 at 11:33

1 Answers1

0

Before you can set the text of a title, the title has to exist for the axis else you get a 424, so the following guarantees there is a title instance to set

ActiveChart.Axes(xlValue, xlPrimary).HasTitle = True

then you can add a value to ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text

gotta love microsoft

JohnnieL
  • 1,192
  • 1
  • 9
  • 15