View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Using If Statements and a Time Variable

Another way:

Public Sub Time_Test2()
Select Case Time
Case Is < #12:00:00 PM#
MsgBox "Good Morning"
Case Is < #6:00:00 PM#
MsgBox "Good Afternooon"
Case Else
MsgBox "Good Evening"
End Select
End Sub


In article ,
OssieMac wrote:

Hopefully third time lucky. I had the time of second case statement
overlapping the third case. Anyway Ihave now included a line where you can
enter dummy values for the time to test it and when finished testing, delete
the line.

Sub Time_Test()
Dim myTime As Date 'Note time is actually a fraction of a date
Dim myMsge As String

myTime = Now - Date 'Now returns date and time. Date returns date only.

'Can uncomment and use following line for testing then delete it
'myTime = TimeValue("23:59:59")

Select Case myTime
Case TimeValue("00:00:00") To TimeValue("11:59:59")
myMsge = "Good Morning"
Case TimeValue("12:00:00") To TimeValue("17:59:59")
myMsge = "Good Afternoon"
Case TimeValue("18:00:00") To TimeValue("23:59:59")
myMsge = "Good Evening"
End Select

MsgBox myMsge

End Sub

regards,

OssieMac