Need a little help with my code: Run my code if time falls in category. Thank you for helping.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
If time in Cells(1, 1) falls between 1 PM - 1:45 AM next day then call macro1 else no.

Code:
Sub timeTRY()
 If Cells(1, 1).Value < "12:00" Then
  MsgBox "Time < 12 PM :)"
   Exit Sub
     Else
    Call Macro1
  End If
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Is it something like this?
Code:
Sub timeTRY()
 
  If Cells(1, 1) < Date + TimeValue("13:00:00") Then
    MsgBox "Too early"
  ElseIf Cells(1, 1) > Date + 1 + TimeValue("01:45:00") Then
    MsgBox "Too late"
  Else
    MsgBox "In range"
  End If
 
End Sub
 
Upvote 0
a1 = 4:00:00 PM but the code does not work as it should/i thought should work...:biggrin:

msgbox "in range" does not show up:
 
Upvote 0
Are you running the macro by hand?

Is the date in there as well?
 
Upvote 0
Hi, Possibly !!
Code:
If Date = "My Date" Then
Application.OnTime TimeValue("17:00:00"), "my_Procedure"
End If
Mick
 
Upvote 0
Code:
Private Sub Workbook_Open()
timeTRY
End Sub

Yes for now i am manually running it but latter it will as above.
in addition my issue...how can i structure this formula

=if(and(A1>A2,A1<A2),"Y","N")< p> by not putting it this way? but like the way you have done it???

Code:
Sub Macro1()
Range("B3").Select
    ActiveCell.FormulaR1C1 = _

        "=IF(AND(RC[-1]>R[1]C[-1],RC[-1].....<R[1]C[-1]),""Y"",""N"")"< p>     Range("B2").Select
End Sub
 
Last edited:
Upvote 0
Hi, Possibly !!
Code:
If Date = "My Date" Then
Application.OnTime TimeValue("17:00:00"), "my_Procedure"
End If
Mick

Mike, thanks for suggestion but i want different user to manually run this code from their respective systems....however only between this time. 1:00 PM to 1:45 AM next day:

So running this code everyday @ 17hrs will create a problem.....
 
Upvote 0
And cell A1 has a date in it as well as a time, yes?

At the moment no date but if that can solve the problem then yes...there is Date and time 10/6/2010 12:00:00 AM format...:)

Thanks again!
 
Upvote 0
Hold on, let me check what you really want to do...

1) Check that the date/time in cell A1 falls between 13:00 on the day you open the workbook and 01:45 the following day?

2) Check that the date/time you open the workbook is before 01:45 or after 13:00 on the current day?
 
Upvote 0

Forum statistics

Threads
1,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

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