Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 533
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I subtract time where hh:mm:ss:ff (frames = 30 frames/sec) KJ7 Excel Discussion (Misc queries) 14 December 3rd 16 10:03 AM
Counting time-frames Ken G. Excel Discussion (Misc queries) 2 August 12th 08 01:11 PM
2 Lists but different time frames. Joel Excel Programming 1 November 10th 07 09:25 PM
check ocontrols within frames within userform Susan Excel Programming 7 March 19th 07 08:01 PM
Calculation of Hrs and Mins from 2 Time Frames Corey Excel Worksheet Functions 6 May 31st 06 05:12 PM


All times are GMT +1. The time now is 09:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"