LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Using If Statements and a Time Variable

On Oct 31, 1:25 am, JE McGimpsey wrote:
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- Hide quoted text -


- Show quoted text -


That works too. Thanks alot for your help. Again, I was not aware of
the "Select Case" statement, but will definitely use it from now on.

Sincerely,
RichG

 
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
IF Statements and Time [email protected] Excel Worksheet Functions 4 May 6th 06 06:44 AM
Variable SQL Statements pulling from a cell in Excel Duke Carey Excel Worksheet Functions 2 March 23rd 06 09:35 AM
Variable SQL Statements pulling from a cell in Excel Duke Carey Links and Linking in Excel 2 March 23rd 06 09:35 AM
Variable SQL Statements pulling from a cell in Excel Duke Carey Excel Worksheet Functions 0 March 22nd 06 08:31 PM
Variable SQL Statements pulling from a cell in Excel Duke Carey Links and Linking in Excel 0 March 22nd 06 08:31 PM


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

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"