Write and IF THEN if cell is between two times

Gesyca_is_joy

Board Regular
Joined
Apr 24, 2014
Messages
90
Office Version
  1. 365
Platform
  1. Windows
I receive a large file each month which tracks staff who badge through a particular badge reader. I am trying to write a formula to tell me if each row was captured during regular business hours or not. below you see a paste of my excerpt (I cannot attach a sample excel file to this for some reason). I keep getting a response in Column C of FALSE, or "Off Hours" no matter the time. I think it has to do with the fact that i get this as unformatted data and cannot format column B to a time format (wanted 24hr) but i'm dealing with upwards of 60k rows per report so i can't manually make that column a time format line by line.

my Formula is: =IF(AND(B2>$H$1,B2<$H$2),"Yes","Off Hours")

H1 = 06:00:00 AM
H2 = 07:00:00 PM

A B C
[TABLE="width: 243"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Date[/TD]
[TD]Time[/TD]
[TD]Work Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 12:51:08AM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 5:47:06AM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 6:22:05AM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 8:01:06AM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 12:55:53PM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 4:52:20PM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 5:51:56PM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 6:50:08PM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 8:48:20PM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 11:47:05PM[/TD]
[TD]Off Hours[/TD]
[/TR]
[TR]
[TD="align: right"]7/10/2018[/TD]
[TD] 12:45:53PM[/TD]
[TD]Off Hours[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
That would suggest your time in the table is text not a real time. Test it by formatting one to number. If it doesnt change its text not time.
 
Upvote 0
That would suggest your time in the table is text not a real time. Test it by formatting one to number. If it doesnt change its text not time.


I tested and it is text. I am not sure how to address this now to get the results I need? can i copy and paste special into a new sheet to get that value to time/number? I can't edit the rows individually as this is a repeat report and quite large.
 
Upvote 0
You could convert them relatively simply:

=0+REPLACE(B2,LEN(B2)-1,0," ")
 
Upvote 0
Ok get rid of the 0+ from the front of the formula. What does it produce?
 
Upvote 0
Ok get rid of the 0+ from the front of the formula. What does it produce?

it produces the value with a space between the last number and the AM/PM

12:51:08PM = 12:51:08 PM

still doesn't allow my original formula to differentiate between working hours and off hours, and I cannot format the results to a TIME format like a 24hr HH-MM-SS format
 
Upvote 0
What about:

=0+TRIM(REPLACE(A1,LEN(A1)-1,0," "))


I tried that as well prior to asking; not with a formula but i used Ctrl+H to replace "Pm" with " PM" and then also to remove the AM and PM. it still didn't work and once you remove the AM and PM you have no way to tell if the time is afternoon or morning because its on a 12 hour clock not a 24 hour.
 
Upvote 0

Forum statistics

Threads
1,224,745
Messages
6,180,699
Members
452,994
Latest member
Janick

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