Run Macro on condition(cases) and Time Both

Nilesh singh

New Member
Joined
Aug 18, 2017
Messages
4
Hi,

I want to combine this two VBA. So that macro should be executed when conditions are met and on time allotted to it.

Private Sub Workbook_Open()
Application.OnTime TimeValue("00:08:00"), "Macro 1"
Application.OnTime TimeValue("00:08:02"), "Macro 2"
End Sub



Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If IsNumeric(Target) And Target.Address = "$B$1" Then
Select Case Target.Value
Case Is < 5: Macro 1
Case Is > 5: Macro 2
End Select
End If
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I don't believe they would combine very well for your purposes. They rely on two completely separate events in two separate code modules to initiate them, both of which are logical for for the desired result. It appears that you want the OnTime event to run when the workbook is first opened in the AM and the other to initiate when if a change occurs in cell B1 of a worksheet. My advice would be to leave it as is.
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,047
Members
449,206
Latest member
Healthydogs

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