update a single chart multiple times as a macro runs

glad_ir

Board Regular
Joined
Nov 22, 2020
Messages
88
Office Version
  1. 2010
Platform
  1. Windows
Hello,

Hoping somebody can help me please.

Is there a command I can include in a macro that will update a chart?

I have a macro that adds data into a worksheet and the added data is used in a Chart (Chart name is Chart 17). The macro adds 1 data point at a time, pauses for 1 second then adds the next data point and so on. Currently my chart only updates once the macro finishes. Is there a way to force the chart to update after each data point is added?

Any help is much appreciated.

Thank you,
Iain
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,142
Office Version
  1. 365
Platform
  1. Windows
Inside your timer loop:

DoEvents

will allow Excel to update the chart.
 

glad_ir

Board Regular
Joined
Nov 22, 2020
Messages
88
Office Version
  1. 2010
Platform
  1. Windows
Inside your timer loop:

DoEvents

will allow Excel to update the chart.
Hi Stephen,

Thank you very much for replying. I have added "DoEvents" into the code as 3 places but it does seem to make a difference. The code runs as before and the chart doesn't update until the end of the code. Do I need to add anything else?

thanks, Iain
 

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,142
Office Version
  1. 365
Platform
  1. Windows
Here's a simple example of what I had in mind, which works for me in Excel 2010: Draw graph

1611530582028.png


VBA Code:
Sub DrawGraph()

    Dim t As Double
    Dim i As Long
  
    For i = 2 To 12
        Range("A2:A" & i).Name = "x"
        Range("B2:B" & i).Name = "y"
        t = Timer + 1
        Do While Timer < t
            DoEvents
        Loop
    Next i

End Sub

How are you adding data points? Coding your 1 second pauses?
 

Watch MrExcel Video

Forum statistics

Threads
1,132,981
Messages
5,656,214
Members
418,290
Latest member
ArrArkRE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top