stanhilliard
12-01-2019, 02:19 PM
I use Excel VBA to run a simulation which cycles through an algorithm multiple times. After each cycle, I want to update the markers of one data series on a scatterchart. The position of that one line is the only thing I need to update. Currently, an un-updated simulation takes 12 seconds. With with the following code it takes 39 seconds -- and a lot of flickering.
Here is what I tried:
In Macro1:
Application.ScreenUpdating = True
Cells(35 + k, 3) = "TIME =" & Format(CSng(Time - StartTime), "h:m:s") & " (Hrs:Min:Sec)"
Call Refreshchart
Application.ScreenUpdating = False
In Sub:
Sub Refreshchart() 'doesn't work.
'ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Chart.Refresh
End Sub
OR:
Sub Refreshchart() 'flickers, takes long time.
ActiveSheet.ChartObjects("Chart 2").Activate
'ActiveSheet.ChartObjects("Chart 2").Chart.Refresh
End Sub
Here are the results:
11 seconds
no Sub
11 seconds, no effect, does not work.
ActiveSheet.ChartObjects("Chart 2").Chart.Refresh
39 seconds
ActiveSheet.ChartObjects("Chart 2").Activate
Q - How can I do this more efficiently?
Here is what I tried:
In Macro1:
Application.ScreenUpdating = True
Cells(35 + k, 3) = "TIME =" & Format(CSng(Time - StartTime), "h:m:s") & " (Hrs:Min:Sec)"
Call Refreshchart
Application.ScreenUpdating = False
In Sub:
Sub Refreshchart() 'doesn't work.
'ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Chart.Refresh
End Sub
OR:
Sub Refreshchart() 'flickers, takes long time.
ActiveSheet.ChartObjects("Chart 2").Activate
'ActiveSheet.ChartObjects("Chart 2").Chart.Refresh
End Sub
Here are the results:
11 seconds
no Sub
11 seconds, no effect, does not work.
ActiveSheet.ChartObjects("Chart 2").Chart.Refresh
39 seconds
ActiveSheet.ChartObjects("Chart 2").Activate
Q - How can I do this more efficiently?