Pause vba for 20 seconds

ste33uka

Active Member
Joined
Jan 31, 2020
Messages
473
Office Version
  1. 365
Platform
  1. Windows
I have the following vba code that runs every 5 minutes
Would it be possible to pause it for 20seconds after the line
.Range("BO2:CC2").Value = Application.Transpose(.Range("O5:O19").Value)
And that excel would not be frozen?
Thanks
VBA Code:
Sub test()

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
   

    With Sheet1
        .Range("BO2:CC2").Value = Application.Transpose(.Range("O5:O19").Value)
    End With
    With Sheet2
        .Range("BO2:CC2").Value = Application.Transpose(.Range("O5:O19").Value)
    End With
    With Sheet3
        .Range("BO2:CC2").Value = Application.Transpose(.Range("O5:O19").Value)

       
    With Sheet1
        .Range("BO8:CC8").Value = Application.Transpose(.Range("O5:O19").Value)
    End With
    With Sheet2
        .Range("BO8:CC8").Value = Application.Transpose(.Range("O5:O19").Value)
    End With
    With Sheet3
        .Range("BO8:CC8").Value = Application.Transpose(.Range("O5:O19").Value)
  
  

    Application.OnTime Now + TimeValue("00:05:00"), "test"

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub
 
That is a harsh/misleading statement.

You make it sound like it 'breaks' the script.

In reality, after the 'Wait' time has elapsed, Excel execution continues normally.
It's not misleading at all. Lock/freeze doesn't mean 'break' the script; they mean the Excel UI is unresponsive. And your line of correct code won't break the script.

The OP asked for a pause which won't freeze Excel and an Application.Wait for 20 seconds will lock/freeze Excel. The crucial thing is the DoEvents, which allows Windows to process mouse and keyboard events, and to set Application.ScreenUpdating = True, which should allow you to select/scroll sheets/cells, enter cell data, etc. whilst the pause loop is running.
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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