Conditions Based on system time.

Drumin_Phreak

New Member
Joined
Oct 10, 2016
Messages
25
Hello,


My goal is to have a condition based on time:

if the system time is 7:00 AM to 3:15 PM "First" would display in the 4th row of column P. However if the time is 3:15:01 pm - 11:15 pm "Second" would be displayed, and "Third" would follow if the time was 11:15:01 pm - 6:59:59.

This task has proven to be a lot more difficult than previously thought. If you would not mid viewing my code and help me figure out why this will not work, i would appreciate it.


Code:
       If Time >= #7:00:00 AM# And Time <= #3:15:00 PM# Then    
        
Range("P4").Value = "First"
    
    ElseIf Time >= #3:15:01 PM# And Time <= #11:15:00 PM# Then
     
Range("P4").Value = "Second"




ElseIf Time >= #11:15:01 PM# And Time <= #6:59:00 AM# Then
     "
Range("P4").Value = "Third"




    End If


Thank you,

Eric
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi, I think this is probably what you want.

Code:
Select Case Time
  Case Is >= #11:15:00 PM#, Is < #7:00:00 AM#: Range("P4").Value = "Third"
  Case Is >= #3:15:00 PM#: Range("P4").Value = "Second"
  Case Else: Range("P4").Value = "First"
End Select
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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