Run a code after delay
Ever wondered how to insert a delay while running a code.
In this blog I'll explain how to add delay before running a code.
Assumption:
A delay of 25 seconds needs to added before running the code.
Steps:
1. Open a new file
2. Press Alt+F11 to open VBA editor
3. In the left navigation window select ThisWorkbook
4. In the editor window enter the code below
5. Close the VBA editor
6. Save the file as Macro Enabled File
7. Test with you inputs
Code:
Sub InsertDelay()
Dim Delay As Variant
Dim Start As Variant
Delay = 25 'Change the value here for required delay in seconds
Start = Timer
Do While Timer < Start + Delay
Loop
End Sub
I think this has been informative and I thank you for viewing.
-Saurabh
Attachment | Size |
---|---|
InsertDelay.xlsm | 11.66 KB |
- saurabhlakhanpal's blog
- Login or register to post comments
- 3951 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago