1

Problem: Refresh graphical representaion of Series in ChartObject after each iteration of for loop

Ex. y=m*Cos(x) 
y - Values
m - parameter

I have some data counted from formula with parameter. I want to visualise what influence has the change of parameter on XYgraph. I want to do it in for loop (added Sleep do have some time to see results). Data and formula are in Excel SpreadSheet. Update script of parameter is in VBA module. Update works on values in spreadsheet but doesn't affect graph.

WorkBook.RefreshAll doesn't work; Chart.Refresh doesn't work

Chart updates after last iteration.

Any ideas?

2 Answers 2

1

Add a DoEvents to your code after each iteration step. It works for me.

Sign up to request clarification or add additional context in comments.

2 Comments

Thx Vacip. Works like a charm! DoEvents works. DoEvents+Sleep is dead.
You can try application.wait instead of sleep. The drawback is that the minimum time is one second there. The upside is that it is not dependant on CPU ticks (sleep is).
0

In Excel for Office 365 I got XYChart live updating working only this way (XYChart to be updated during/in the end of each For loop iteration round). I could not get Sleep() working at all. Unfortunately Application.Wait tick resolution is 1 second, so the animation may be relatively slow. Also <chartObject>.Chart.Refresh did not have desired effect (for auto updating during the For loop).

Note: Some of the codes below may not be necessary in your case (at least Application.ScreenUpdating should be ON by default).

Application.ScreenUpdating = True    
ActiveSheet.ChartObjects(1).Activate

...

    For i = 1 To 10
       'Chart source data cells manipulation/update and other chart related routines here.'

       ActiveSheet.ChartObjects(1).Activate
       Application.Wait (Now + TimeValue("00:00:01"))
       DoEvents
   Next i

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.