ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA syntax to check between two time frames i.e. 2 PM thru 5 AM? (https://www.excelbanter.com/excel-programming/406062-vba-syntax-check-between-two-time-frames-i-e-2-pm-thru-5-am.html)

lwchapman

VBA syntax to check between two time frames i.e. 2 PM thru 5 AM?
 
I am using a worksheet code page and would like to check if the current time
of day falls between 2:00:00 PM thru 5:00:00 AM. If true, then a procedure
would be executed. If false, the procedure would not run. I am having
trouble with my syntax and cannot find the correct coding, function or "how
to" in MS Help.

I am using Excel in Office 2007 Professional.

I would greatly appreciate any suggestions one might have to offer in
resolving this issue.

Thanking all in advance, Larry

Peter T

VBA syntax to check between two time frames i.e. 2 PM thru 5 AM?
 
Sub test()
Dim t1 As Date, t2 As Date
Dim tm As Date

tm = Now

''' also uncomment each of the following starting from
''' the top to test

'tm = TimeSerial(5, 0, 0)
'tm = TimeSerial(5, 0, 1)
'tm = TimeSerial(13, 59, 59)
'tm = TimeSerial(14, 0, 0)

If tm 1 Then
tm = tm - Int(tm)
End If

If tm = TimeSerial(14, 0, 0) Or tm <= TimeSerial(5, 0, 0) Then
MsgBox "Do it", , tm
Else
MsgBox "skip it", , tm
End If

End Sub

Regards,
Peter T
"lwchapman" wrote in message
...
I am using a worksheet code page and would like to check if the current

time
of day falls between 2:00:00 PM thru 5:00:00 AM. If true, then a

procedure
would be executed. If false, the procedure would not run. I am having
trouble with my syntax and cannot find the correct coding, function or

"how
to" in MS Help.

I am using Excel in Office 2007 Professional.

I would greatly appreciate any suggestions one might have to offer in
resolving this issue.

Thanking all in advance, Larry




Jim Rech[_2_]

VBA syntax to check between two time frames i.e. 2 PM thru 5 AM?
 
Maybe:

If Hour(Now) = 14 Or Hour(Now) < 5 Then

--
Jim
"lwchapman" wrote in message
...
|I am using a worksheet code page and would like to check if the current
time
| of day falls between 2:00:00 PM thru 5:00:00 AM. If true, then a
procedure
| would be executed. If false, the procedure would not run. I am having
| trouble with my syntax and cannot find the correct coding, function or
"how
| to" in MS Help.
|
| I am using Excel in Office 2007 Professional.
|
| I would greatly appreciate any suggestions one might have to offer in
| resolving this issue.
|
| Thanking all in advance, Larry




All times are GMT +1. The time now is 04:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com