0

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 
5
  • What issue are you actually having - is it not working, do you get an error...? Commented Jan 30, 2016 at 11:12
  • Hello Alex. Thank you for your response. I am having an error of "Run-time error '91': Object variable or With block variable not set" What I actually have is 2 sheets, 1: is the chart data which I put all the data for the chart, 2: is where the chart is. Commented Feb 2, 2016 at 1:33
  • You don't identify the ActiveChart. You need to write: With Worksheets("Sheet2").ActiveChart.Axes(xlValue). That worked for me. Commented Feb 2, 2016 at 9:35
  • Private Sub Worksheet_calculate() With Worksheets("Chart").ActiveChart.Axes(xlValue) .MinimumScale = Worksheets("Chart Data").Range("E111").Value End With End Sub Is this how it is? I got an error: "Run-time eror 438: Object doesn't support this property or method." Commented Feb 4, 2016 at 5:32
  • How is E111 getting calculated? The issue is with ActiveChart. If you are in Chart Data when the calculation happens then you get an error as the chart is not active. Instead, try referencing the chart directly by name... Commented Feb 4, 2016 at 8:40

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Hello. On the cell "Chart Data" E111, I get the minimum date and pass the value to the minimum axes using the general format value. I try using your code with ChartObjects and its good it throws no error but the minimum axis is not updating. I try to check it manually and it says 0.0
Thank you Alex. I got it now. I used a button to trigger run the vba. Thanks a lot.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.