Home

How to return a 0 in a blank cell-formula

Highlighted
JDEMARIE
Occasional Visitor

Hello all,

 

I have a formula below where I am returning the number of hours (i.e. 12) depending on what's typed in the B column. My question is, if a cell in the B column is blank because the employee is off that day, how do I add to the formula below so it returns a 0 (zero) if the cell is blank?

 

=IFS($B$4:$B$16="7A-7:30P","12","7P-7:30A","12","8A-4:30P","8","1P-7:30P","6","7P-3:30A","8")

 

Thank you all in advance!

 

 

2 Replies

Hi,

 

This formula seems to be incorrect and return the wrong result.

So, I've rebuilt this formula for you to return the correct result and to take into account if the blank cells.

=IFS(OR(B4="7A-7:30P",B4="7P-7:30A"),12,OR(B4="8A-4:30P",B4="7P-3:30A"),8,B4="1P-7:30P",6,B4="",0)

 

Also, you can use the SWITCH function as follows which is shorter:

=SWITCH(B4,"7A-7:30P",12,"7P-7:30A",12,"8A-4:30P",8,"7P-3:30A",8,"1P-7:30P",6,0)

 

IFS VS SWITCH.png

 

Hope that helps

 

Highlighted

If don't use predefined shift, however assume they have the same logic in names, that could be

=IFERROR(((MID(B3,SEARCH("-",B3)+1,LEN(B3)-SEARCH("-",B3)-1)&":00")+(MID(B3,SEARCH("-",B3)-1,1)<>RIGHT(B3,1))*0.5-(LEFT(B3,SEARCH("-",B3)-2) &":00"))*24-0.5,0)