Variable time between Macros

kshines

Board Regular
Joined
Apr 3, 2011
Messages
56
Office Version
  1. 365
Platform
  1. Windows
Dear Wise members of the forum.
Below is a piece of VBA that is working great. I would, however, like to modify it so that it would, after "x" seconds run the Macro one more time. I have put what I would like to happen in bold below.
Any help would be very much appreciated!!!
KH

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Message "Calculating"
If Not Intersect(Target, Range("D4:D15")) Is Nothing Then cal_model1
Timer 1 sec
Run Macro1 again
"Calculation complete"

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I presume that you want to "run macro1 again" only if you run it once in the first place. Something like the following (untested)....

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Const delay As String = "0:0:2"    ' 2 sec delay; 1 sec delay is unreliable
If Not Intersect(Target, Range("D14:D15")) Is Nothing Then
    Application.EnableEvents = False    ' avoids repeated Worksheet_Change calls, if cal_model1 changes range
    Application.ScreenUpdating = False
    Application.StatusBar = Now & "    Calculating...."
    DoEvents
    cal_model1
    Application.Wait Now + TimeValue(delay)    ' see caveat below
    cal_model1
    Application.StatusBar = Now & "    Calculation complete"
    Application.ScreenUpdating = True
    Application.EnableEvents = True
End If

Caveat: While executing Application.Wait, Excel cannot execute. Is that what you want?

Alternatively, use Application.OnTime. But that is not a one-statement replacement. Do you need help with that?
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,714
Members
452,995
Latest member
isldboy

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