Waiting in Excel Macros

Saucepan picture Saucepan · Nov 30, 2015 · Viewed 10.9k times · Source

I am recording an Excel Macro where I would like it to wait half a second before switching to the next value. I am plotting changes to a graph, and right now it just storms through the values so you dont really see any changes. I would therefor like it to wait half a second before moving on.

The Macro Im using looks like this:

Sub Macro2()
' Macro2 Macro
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "2"
    Range("C2").Select
End Sub

Now I would love to do something like the following but it doesnt work.

Sub Macro2()
' Macro2 Macro
    Range("C1").Select
ActiveCell.FormulaR1C1 = "1"
Range("C1").Select
Sleep (100)
ActiveCell.FormulaR1C1 = "2"
Range("C2").Select
Sleep (100)
End Sub

Help please? I'm on a Mac Office Excel 2011.

Answer

Olle Sjögren picture Olle Sjögren · Nov 30, 2015

Try Application.Wait(time). It pauses the macro until the specified time, then returns True.

To wait 1 second:

Application.Wait(Now + TimeValue("0:00:01"))

(Tested in Excel 2010 on Windows)