Change cell contains depends on time and date

borg

New Member
Joined
Aug 20, 2024
Messages
2
Office Version
  1. Prefer Not To Say
Platform
  1. Windows
Hello
I have a little struggle with this
4 employees work at 12 hours shift, day shift 7:30-19:00 (7:30AM-7:00PM) and night shift 19:00-7:30 (7:00PM-7: 30AM)
Question: how to make in cell A1 show employee name depends on date and time?

Thanks in advance
IMG_20240820_150914.jpg



IMG_20240820_150914.jpg
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
in cell A1 show employee name depends on date and time
but where is this date/time.
Is it current moment? if yes, use such formula in A1:
Excel Formula:
=INDEX(B4:D34,MATCH(TODAY(),A4:A34,0),MATCH(NOW()-TODAY(),B2:D2,1))

If it is other time, use date in first match and time in second one.

Imprortant remark
Both: dates in column A, and times in row 2 have to be excel dates/times, not just texts looking like date/time. Easy way to check this is by changing formatting to a custom like:
"ddmmyyhhmm"

if such formatting applied to A4 produces
0108240000​
and to C2:
0001000730​
you have real dates and times in respective cells and formula shall work fine.
If not, you have either to transform your data in column A/row 2 to be real times/dates (highly recommended) or ammend formula to deal with texts (possible, but not recommended).
 
Upvote 0
Solution
Thanks, that now()-today() solved everything

Thanks again
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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