kat2000
kat2000

Reputation: 31

VBA Run-time error 91

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

Upvotes: 3

Views: 923

Answers (1)

David912
David912

Reputation: 396

Add the following line before the with statement.

ActiveSheet.ChartObjects("Chart 1").Activate

Assuming "chart 1" is the name of your chart.

Upvotes: 4

Related Questions