I assigned a macro to a shape, but I'm receiving a Run-time error '91' Object variable or With block variable not set. But, when I run the Macro from the Developer tab, it works. The "ActiveChart.Axes" line is where the error is coming from. I'm new to VBA so any help would be appreciated. Should I replace "ActiveChart.Axes" with "ActiveSheet.ChartObjects"?
Option Explicit
Sub ScaleAxes()
With ActiveChart.Axes(xlValue, xlPrimary)
.MaximumScale = ActiveSheet.Range("B14").Value
.MinimumScale = ActiveSheet.Range("B15").Value
.MajorUnit = ActiveSheet.Range("B16").Value
End With
End Sub
Add the following line before the with statement.
ActiveSheet.ChartObjects("Chart 1").Activate
Assuming "chart 1" is the name of your chart.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With