PDA

View Full Version : Update chart after cell gets updated



leal72
10-10-2019, 09:55 AM
Trying to find a way to have the chart update as macro is running. I can see the cells update each time B11 changes but can not get chart to update until marco finishes loop.



Private Sub CommandButton1_Click()

For x = 0 To 44
Range("B11").Value = x
Application.Wait (Now + TimeValue("00:00:03"))
ActiveSheet.ChartObjects("Chart 3").Chart.Refresh
Range("B11").Value = x + 1
Next x



End Sub

paulked
10-10-2019, 11:15 AM
There are many differing thoughts on DoEvents, but it does work in instances like this, but for reliable updating I had to put it in 4 times!

I changed the order of the code to update the chart before the wait command:



Private Sub CommandButton1_Click() Dim x As Long, dummy As Long
For x = 0 To 5
Range("B11").Value = x
ActiveSheet.ChartObjects("Chart 3").Chart.Refresh
DoEvents: DoEvents: DoEvents: DoEvents
Application.Wait (Now + TimeValue("00:00:01"))
Range("B11").Value = x + 1
Next x





End Sub




There are probably better ways to do it, but I can't help there, sorry.

leal72
10-10-2019, 11:54 AM
Thank you for this, I do appreciate it!