Change value of cell based on time of day

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Hello all,

I wasn't sure if this could be done as a formula, but basically, I am looking for something that would return the cell value of "Good morning" from 1:00-12:00, good afternoon from 12:01-17:00, and good evening from 17:01 to 01:00. is there a simple way to do this?

The reasoning behind this is that I have a user form that will greet the user, and the first line is going to be a cell reference, which will hopefully display the appropriate message based on time of day. Although any other creative solutions out there are certainly welcome!

Thanks!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try
Code:
=VLOOKUP(MOD(NOW(),2),{0,"Good Evening";0.0416666666666667,"Good Moring";0.500694444444444,"Good Afernoon";0.709027777777778,"Good Evening"},2)
 
Last edited:
Upvote 0
Are the decimals just the numerical equivalent to time? so 6 AM is .25, noon is .5, etc?
 
Upvote 0
Yes, it is the part of a 24 hour day so 6AM/24=.25 and 13(1PM)/24=.54166. To the left of the decimal would be the date so 42998.54166 would be 9/20/17 1PM.
 
Last edited:
Upvote 0
Code:
=VLOOKUP(MOD(NOW(),[COLOR=#ff0000][B]2[/B][/COLOR]),{0,"Good Evening";0.0416666666666667,"Good Moring";0.500694444444444,"Good Afernoon";0.709027777777778,"Good Evening"},2)

Hi, this should be MOD 1

Here is another option that might be a little more intuitive:

Rich (BB code):
="Good "&LOOKUP(MOD(NOW(),1),0+{"00:00","01:00","12:01","17:01"},{"Evening","Morning","Afternoon","Evening"})
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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