Formula help needed (Total hours worked but skip blank rows)

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,806
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I have the following :


______A____ ____B___________ C

1___Time In______Time Out______Total Hours

2 ____10:00______14:00__________04:00

3 ____23:30______01:45__________02:15

4

5 ____
13:00______14:30__________01:30


The Formula I have in Column C to calculate the total hours is : (filled down the rows below)
=IF(AND(A1="",B1=""),"",IF(AND(A1<>"",B1<>""),(1-A1)+B1,IF(A1>NOW(),0,(1-A1)+NOW())))

Then in cell H1, I am trying to get the sum of total hours as follows :

{=IF(C1:C4<>"",SUM(HOUR(C1:C4)+MINUTE(C1:C4)/60),0)} (Array Formula)

Cell H1 containing the array formula is is Number-formatted as General.

The array formula works well except if the cells in row 4 (ie both cells A4 AND B4) are blanks

In other words, If row 4 is blank as in the above table then the formula returns #VALUE ! error as it is trying to sum blank cells.

Can someone solve this without using a helping column ?

Thank you.
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hello Jaafar,

In cell C2 ... you could have =MOD(B2-A2,1)

In cell H2 ... is following array formula of any help : =SUM(C2:C5)

Hope this will help
 
Upvote 0
@James006

Sorry for the late reply.

I altered your suggestion slightly as follows :

In cell C1 .... =IF(MOD((1-A1)+B1;1)=0;"";MOD((1-A1)+B1;1))
In Cell H1 .... =HOUR((SUM(C1:C5)))+MINUTE(SUM(C1:C5))/60

This works and doesn't display the #VALUE error when a row is blank BUT Cell H1 gives the wrong result when the TimeOut is after midnight .

Any thoughts ?

Thank you.
 
Last edited:
Upvote 0
Hello Jaafar,

Just tested in cell H1 ... format as General ...

=HOUR(SUM(C1:C5))+MINUTE(SUM(C1:C5))/60

and everything is fine ...:wink:
 
Upvote 0
Works like a charm !

I must have done something wrong when testing the last formula I posted as it is the same.

Anyway, thank you very much for your kind assistance.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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