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
DateTimeWork Hours
7/10/2018 12:51:08AMOff Hours
7/10/2018 5:47:06AMOff Hours
7/10/2018 6:22:05AMOff Hours
7/10/2018 8:01:06AMOff Hours
7/10/2018 12:55:53PMOff Hours
7/10/2018 4:52:20PMOff Hours
7/10/2018 5:51:56PMOff Hours
7/10/2018 6:50:08PMOff Hours
7/10/2018 8:48:20PMOff Hours
7/10/2018 11:47:05PMOff Hours
7/10/2018 12:45:53PMOff Hours

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
it produces 11., each field has a leading space. even if i trim the spaces out from the field, and then format as TIME it doesn't change the field value.


Ok, so i Trimmed the leading space, then i used ctrl+h to replace "PM" with " PM" then i formatted to time and 24 hour, so that 2:51:08 PM then became 14:51:08 and made sure my "start" and "end times" were formatted the same way and it worked!!!

ok so i know i can use the ctrl+h to manually insert spaces in the AM and PM part of this. and I will TRIM each field to remove the leading spaces. I will create a new column with the formula to remove the leading space and insert a space in front of AM/PM. THEN i will write my IF then off that new value.
 
Last edited:
Upvote 0
Ok...well If i use trim then insert a space before AM/PM and format as TIME it still doesn't work. it only works if i manually click into the cell and delete the space....what am i doing wrong?
 
Upvote 0
Welp, I got it working by using the steps above to manually remove and add spaces where needed.....then found out this is in GMT and need to convert to CST to report out with (it's always something)

So, created a new column and used the formula: =B2+1-TIME(6,0,0) to convert to CST. rewrote my ORIGINAL formula to calculate whether working hours or off hours from from CST column not the original GMT column......and........they all came up false..... Why is this so hard??
 
Upvote 0
You need to find out what that character is:

=CODE(LEFT(B2,1))

produces what?
 
Upvote 0
You need to find out what that character is:

=CODE(LEFT(B2,1))

produces what?


on Cell B2,11:58:05 PM, I return the value of 12:00:00 AM

on Cell C2: 5:58:05 PM, derived from the formula: =B2+1-TIME(6,0,0), I return the value of 12:00:00 AM as well
 
Upvote 0
So there is no leading space? You need to help me out here cause you are taking me round in circles. Based on the original data do nothing to the contents of the cell at all unless i say. No ctrl-h. No nothing. What does the formula:

=CODE(LEFT(B2,1))

produce?
 
Upvote 0

Forum statistics

Threads
1,215,366
Messages
6,124,514
Members
449,168
Latest member
CheerfulWalker

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