How to total hours per employee from a timesheet in Excel
Formula (Excel and Google Sheets)
=SUMPRODUCT(($A$2:$A$10=F2)*($D$2:$D$10-$C$2:$C$10))*24Sum each person's out-minus-in with SUMPRODUCT and convert to hours: =SUMPRODUCT(($A$2:$A$10=F2)*($D$2:$D$10-$C$2:$C$10))*24.
- Result on the example
- one result per row in
G2, filled down toG4 - Works in
- Excel 2021, 2024 and Microsoft 365
- Google Sheets
- Same formula
See it work
The formula is already in G2, filled down to G4. Change any input and the result updates, or edit the formula to experiment.
How it works
$D$2:$D$10-$C$2:$C$10 is each shift's length as a fraction of a day. Multiplying by the test for the employee keeps only that person's shifts, SUMPRODUCT adds them, and *24 turns days into hours: Ana worked 26 hours.
=SUMPRODUCT(($A$2:$A$10=F2)*($D$2:$D$10-$C$2:$C$10))*24Result26
$A$2:$A$109 rows × 1 col: "Ana", "Ben", "Cara", "Ana", …A range: 9 cells in one column.
F2"Ana"The value in F2.
$A$2:$A$10=F2{9 rows × 1 col} TRUE, FALSE, FALSE, TRUE, …The = operator tests whether the two sides are equal.
$D$2:$D$109 rows × 1 col: 4:30 PM, 5:15 PM, 3:00 PM, 5:00 PM, …A range: 9 cells in one column.
$C$2:$C$109 rows × 1 col: 8:00 AM, 9:00 AM, 7:30 AM, 8:00 AM, …A range: 9 cells in one column.
$D$2:$D$10-$C$2:$C$10{9 rows × 1 col} 0.3541666667, 0.34375, 0.3125, 0.375, …The - operator subtracts.
$A$2:$A$10=F2)*($D$2:$D$10-$C$2:$C$10{9 rows × 1 col} 0.3541666667, 0, 0, 0.375, …The * operator multiplies.
SUMPRODUCT(($A$2:$A$10=F2)*($D$2:$D$10-$C$2:$C$10))1.083333333SUMPRODUCT: Multiplies arrays row by row and adds the results.- array1
$A$2:$A$10=F2)*($D$2:$D$10-$C$2:$C$10{9 rows × 1 col} 0.3541666667, 0, 0, 0.375, …
- array1
SUMPRODUCT(($A$2:$A$10=F2)*($D$2:$D$10-$C$2:$C$10))*2426The * operator multiplies.
In Google Sheets
The same formula works in Google Sheets: =SUMPRODUCT(($A$2:$A$10=F2)*($D$2:$D$10-$C$2:$C$10))*24. We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =SUM(FILTER($D$2:$D$10-$C$2:$C$10,$A$2:$A$10=F2))*24 | 26.00, 20.75, 23.50 | FILTER version for Excel 365 and Google Sheets. |
Common mistakes
- SUMIFS can't subtract two columns. Use SUMPRODUCT, as here, or add an hours column and SUMIFS that.
- Night shifts need MOD:
MOD($D$2:$D$10-$C$2:$C$10,1).
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Total hours per employee from a timesheet
G2, total the hours worked by the employee in F2, from the in and out times, and fill down to G4.Questions
How do I total by employee and week?
Add a date test, like *(dates>=week_start)*(dates<week_start+7).
How do I show the total as hours and minutes?
Leave out *24 and use the custom format [h]:mm, so totals over 24 hours don't wrap.
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.