add a delay to this macro and pause it if it gets to 6pm?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,201
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have this macro that runs on (I think its called a loop?)

now it works great but for reasons that are hard to describe (lets call then office politics) I need it to do the following,
each time it gets to here "Next Cl" I would like it to wait 90 seconds before proceeding please.

but also before it proceeds I'd like it to check if its 6pm or later and if it is then pause the macro
and messagebox me "Macro paused do you want to continue?"

the code is below,
please help if you can as I cant go home until i've sorted this out :(

Thanks

Tony



VBA Code:
Sub Add_All_Condition_Sheets1() 'add sheets in a list
   Dim Cl As Range
   
   Application.ScreenUpdating = False
   With Sheets("Key Risks")

'      For Each Cl In .Range("H1", .Range("H" & Rows.Count).End(xlUp))
      For Each Cl In .Range("B2:B56")
         Sheets("Master").Copy , Sheets(Sheets.Count)
         ActiveSheet.Name = Cl.Value
         ActiveSheet.Range("AF2").Value = Cl.Offset(, 1).Value
      Next Cl ' SO Here I would like it to wait 90 seconds before proceeding please
'then here I need it to check that its not 6pm or later, if it is, the pause the macro
create a pop up box that says "Macro Pause Continue?" and a yes no Box
if yes then it continues if no it just closes down and exits.




   End With
   Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
normally you something like this with application.ontime, but you asked to "wait" so ...
VBA Code:
Sub Add_All_Condition_Sheets1()                                 'add sheets in a list

     Dim Cl    As Range

     Do 'start infinite loop
          Application.ScreenUpdating = False
          With Sheets("Key Risks")

     '      For Each Cl In .Range("H1", .Range("H" & Rows.Count).End(xlUp))
               For Each Cl In .Range("B2:B56")
                    Sheets("Master").Copy , Sheets(Sheets.Count)
                    ActiveSheet.Name = Cl.Value
                    ActiveSheet.Range("AF2").Value = Cl.Offset(, 1).Value
               Next Cl

               Application.Wait Now + TimeSerial(0, 0, 90)      'wait 90 sec
               If Now - Date >= TimeSerial(18, 30, 0) Then
                    answ = MsgBox("macro pause/continu", vbYesNo, UCase("After 18:30 PM"))
                    If answ <> vbYes Then Exit Sub              'no = stop and exit
               End If
          End With
          Application.ScreenUpdating = True
     Loop

End Sub
 
Upvote 0
I’d include Application.ScreenUpdating = True before Exit Sub.
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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