Time Delay not working...

bapcki1

New Member
Joined
Nov 12, 2011
Messages
39
Hi Everyone,

I can't seem to get a time delay to work. I thought it wouldn't be too difficult but all i want to do is: as part of a macros that is triggered by a calculation result equalling 1, at first cell A4 = 0 and then at the end of the macros, after a 10 second pause cell A4 = 95.

Why doesn't this code work! (ARRRGHH!!)

In Sheet 1

Code:
Option Explicit
 
Sub Wait(tSecs As Single)
     '   Timer to create a pause
    Dim sngSec As Single
     
    sngSec = Timer + tSecs
    Do While Timer < sngSec
        DoEvents
    Loop
End Sub

Private Sub Worksheet_Calculate()
If [K36] = 1 Then
ThisWorkbook.Sheets("Sheet1").Range("A4").Value = "0"
Range("A1").Copy
    Range("E1").PasteSpecial xlPasteValues
ThisWorkbook.Sheets("Sheet1").Range("K36").Value = "0"
Range("A1").ClearContents
Wait 10
ThisWorkbook.Sheets("Sheet1").Range("A4").Value = "95"
End If
End Sub

What happens is: Cell A4 does as it is supposed to but at the end of the macros instead of just deleting the contents of A1 (as it is supposed to) it also clears cell E1 but then the macros doesn't stop, I have to go into the VBA editor > run > break to stop it..????

Any help is greatly appreciated!

Thank you!

Paddy
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
For your Wait 10 procedure, I would use:

Code:
Application.Wait Now + TimeValue("0:0:10")

you might be running into problems since Wait is a built-in method (of the Application object).I am using it above, and most importantly, in a different way than you.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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
Back
Top