Results 1 to 1 of 1

Thread: Updating a Chart while VBA is running

  1. #1

    Updating a Chart while VBA is running

    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

    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?
    Last edited by stanhilliard; 12-01-2019 at 02:25 PM. Reason: to clarify.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts