Jandhell Colipano
Jandhell Colipano

Reputation: 3

Set minimum value on chart axis using VBA

Can you help me with this? I want to generate a minimum axis value for my chart based on a cell reference.

Here is my code.

Private Sub Worksheet_calculate()
   With ActiveChart.Axes(xlValue)
       .MinimumScale = Worksheets("Chart Data").Range("E111").Value
   End With
End Sub

Upvotes: 0

Views: 9919

Answers (1)

Alex P
Alex P

Reputation: 12497

I'd do it this way:

Private Sub Worksheet_calculate()
    Dim cht As Chart

    Set cht = Worksheets("Chart").ChartObjects("Chart 1").Chart

    cht.Axes(xlValue).MinimumScale = Worksheets("Chart Data").Range("E111").Value
End Sub
  • Set up a reference to your chart object so you don't need ActiveChart
  • You may need to update ChartObjects("Chart 1") with the name of your chart
  • You can also index it so if you only have one chart on the page you can use ChartObjects(1)

Upvotes: 3

Related Questions