# Calculate time in excel

#### JoeyGaspard

##### Board Regular
I get a text report from our time keeping system that i dump into excel through a data connection and I need to calculate the total hours for a day, the problem is, some employees clock in and out for lunch, so there could be up to 4 punches per day per employee. I am trying to automate it so that it will subtract the clockin time from the lunch clock out time, and the lunch clock in from the end of the day clockout to give me total hours worked for the day. Example, if I have these 4 times:
7.82
12.60
13.02
16.66
I need to subtract 7.82 from 12.60 and 13.02 from 16.62, and then add the two numbers together for the total for the day. I have no problem doing this if everyone clocked 4 punches a day, but some clock 2 times, and others 4, just depends on whether they leave for lunch. I get the data with a date and time stamp, is there a way to do this either with vba or a formula? I need excel to recognize whether there are 2 or 4 punches so it will know what to subtract from what? Any help is greatly appreciated! Here is an example of what the data looks like:

 19999 2021-04-05 07:49:19.000 CLARK LEAH 07:49:19.000 19999 2021-04-05 12:36:11.000 CLARK LEAH 12:36:11.000 19999 2021-04-05 13:01:25.000 CLARK LEAH 13:01:25.000 19999 2021-04-05 16:39:43.000 CLARK LEAH 16:39:43.000 19999 2021-04-06 07:46:02.000 CLARK LEAH 07:46:02.000 19999 2021-04-06 12:30:33.000 CLARK LEAH 12:30:33.000 19999 2021-04-06 13:06:53.000 CLARK LEAH 13:06:53.000 19999 2021-04-06 16:46:06.000 CLARK LEAH 16:46:06.000 19999 2021-04-07 07:55:45.000 CLARK LEAH 07:55:45.000 19999 2021-04-07 11:38:46.000 CLARK LEAH 11:38:46.000 19999 2021-04-07 12:10:14.000 CLARK LEAH 12:10:14.000 19999 2021-04-07 16:30:03.000 CLARK LEAH 16:30:03.000 19999 2021-04-08 07:50:41.000 CLARK LEAH 07:50:41.000 19999 2021-04-08 16:34:03.000 CLARK LEAH 16:34:03.000 19999 2021-04-09 07:18:18.000 CLARK LEAH 07:18:18.000

I convert it 100 minute time also.

### Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

#### JoeyGaspard

##### Board Regular
It may be easier for you to look at the spreadsheet. If you look at the tabs, you will see that sometimes it starts calculating on the first row?

#### JoeyGaspard

##### Board Regular
Sorry, hit post before i was ready! There is quite a bit of vba that refreshes the adminreport-utf8 tab, then moves all the data to the corresponding tabs. Columns A B and C get cleared each time, but Column D (where your formula is remains untouched. Also, I tried adding your formula as an if statement, saying if A1 is blank, then blank, else your formula, but couldnt get it to work.

##### Well-known Member
My functions require that there's an unused row 1 for it to work. That's why I put headings on my data example, and my formulae must start in row 2.

If you can change your VBA to leave row 1 empty and start populating from row 2 it should work.

I see you have a maximum of 30 rows per person so all the \$16 in my formula should be changed to \$30

Would you like me to take your adminreport-utf8 table and provide the calculation in some unused columns there?

#### JoeyGaspard

##### Board Regular

My functions require that there's an unused row 1 for it to work. That's why I put headings on my data example, and my formulae must start in row 2.

If you can change your VBA to leave row 1 empty and start populating from row 2 it should work.

I see you have a maximum of 30 rows per person so all the \$16 in my formula should be changed to \$30

Would you like me to take your adminreport-utf8 table and provide the calculation in some unused columns there?
Awesome! I get it now! I will change my vba to start everything on row 2, and I will change the 16 to 30. Do I still need to put the formula in row 1, or start it in row 2?

##### Well-known Member
Start the formulae in row 2

#### JoeyGaspard

##### Board Regular

Start the formulae in row 2
That works great! Any thoughts on the "if" part? I need for the cell to stay blank if there is nothing in column A, but when I put the if statement in, it doesnt work, here is what I am trying:
=if(a2="",'"",CHOOSE(COUNTIFS(\$A\$1:\$A2,A2,\$B\$1:\$B2,B2),"",24*(C2-INDEX(\$C\$2:\$C\$16,AGGREGATE(15,6,ROW(\$C\$2:\$C\$16)-ROW(\$C\$1)/((\$A\$2:\$A\$16=A2)*(\$B\$2:\$B\$16=B2)),1))),"",24*(C2-INDEX(\$C\$2:\$C\$16,AGGREGATE(15,6,ROW(\$C\$2:\$C\$16)-ROW(\$C\$1)/((\$A\$2:\$A\$16=A2)*(\$B\$2:\$B\$16=B2)),3))))

##### Well-known Member
Looks like you picked up a single apostrophe in your double-quotes.

#### JoeyGaspard

##### Board Regular
Looks like you picked up a single apostrophe in your double-quotes.
omg...so sorry! thank you for everything!

#### JoeyGaspard

##### Board Regular
Looks like you picked up a single apostrophe in your double-quotes.
Hey! I was wondering if you could help me one more time with your formula? It works great for the people who clock in and out on the same day, the problem is, we have people who work nights that clock in before midnight on one day, and clock out after midnight, so that puts them on the following day, and it doesnt calculate them due to the diff in the dates? Example below. TIA

 99232​ 4/11/2021​ 21:59​ 99232​ 4/12/2021​ 5:24​ 99232​ 4/12/2021​ 19:50​ 14.44​ 99232​ 4/13/2021​ 6:28​ 99232​ 4/13/2021​ 19:52​ 13.40​ 99232​ 4/14/2021​ 6:30​ 99232​ 4/14/2021​ 19:58​ 13.47​ 99232​ 4/15/2021​ 6:39​ 99232​ 4/15/2021​ 19:59​ 13.34​ 99232​ 4/16/2021​ 6:46​

Replies
10
Views
90
Replies
3
Views
70
Replies
1
Views
317
Replies
0
Views
268
Replies
11
Views
18K

1,130,119
Messages
5,640,219
Members
417,131
Latest member
Seanr19871

### 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.

### Which adblocker are you using?

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

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