Duplicate Rows

jsmucker24

New Member
Joined
Aug 30, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have a table with Employee time data. For an accuracy check, I need a formula that counts the number of the duplicate employee names with duplicate dates (if any) See the sample table attached)
If I have any duplicate rows then I know that there is a problem because an employee can't work twice in one day.
I was unsuccessful with Chat GPT. Any help would be appreciated. Thank you!
 

Attachments

  • Screenshot 2025-02-20 155120.png
    Screenshot 2025-02-20 155120.png
    15 KB · Views: 10
Here is a VBA answer :

VBA Code:
Sub CheckDuplicates()
    Dim lastRow As Long
    Dim i As Long, j As Long
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Adjust the sheet name if necessary
    
    ' Find the last row with data in column A
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    ' Clear previous highlights
    ws.Range("A1:B" & lastRow).Interior.ColorIndex = 0
    
    ' Loop through each row and compare values in Column A and Column B
    For i = 2 To lastRow ' Start at row 2 to skip header
        For j = i + 1 To lastRow
            If ws.Cells(i, 1).Value = ws.Cells(j, 1).Value And _
               ws.Cells(i, 2).Value = ws.Cells(j, 2).Value Then
                ' Highlight duplicates
                ws.Cells(i, 1).Interior.Color = RGB(255, 0, 0) ' Red highlight for duplicate
                ws.Cells(i, 2).Interior.Color = RGB(255, 0, 0) ' Red highlight for duplicate
                ws.Cells(j, 1).Interior.Color = RGB(255, 0, 0) ' Red highlight for duplicate
                ws.Cells(j, 2).Interior.Color = RGB(255, 0, 0) ' Red highlight for duplicate
            End If
        Next j
    Next i
    
    MsgBox "Duplicate check complete!"
End Sub

And here are two formula answers :
 

Attachments

  • Dupes.jpg
    Dupes.jpg
    31.6 KB · Views: 5
Upvote 0
Book1
ABCDEFGHIJK
1NameDate
2aaaa16-01-2025aaaa16/1/2025, 22/1/2025
3aaaa22-01-2025nnn12-01-2025
4aaaa16-01-2025
5nnn12-01-2025
6aaaa22-01-2025
7nnn12-01-2025
8nnn25-01-2025
9
Sheet1

Only dates are taken and Timings are not taken.
For 365 version in H2
Excel Formula:
=LET(da,A2:A8,db,B2:B8,a,COUNTIFS(da,da,db,db),za,UNIQUE(FILTER(da,a>1)),zb,BYROW(za,LAMBDA(x,TEXTJOIN(", ",1,UNIQUE(FILTER(TEXT(db,"mm/dd/yyyy"),(da=x)*(a>1)))))),HSTACK(za,zb))
My default date format is dd/mm/yyyy
 
Upvote 0
Book1
ABCDEFGHIJK
1NameDate
2aaaa16-01-2025NamesDuplicate Dates
3aaaa22-01-2025aaaa16/1/2025, 22/1/2025
4aaaa16-01-2025nnn12-01-2025
5nnn12-01-2025
6aaaa22-01-2025
7nnn12-01-2025
8nnn25-01-2025
Sheet1

Including the heading formula in H2
Excel Formula:
=LET(da,A2:A8,db,B2:B8,a,COUNTIFS(da,da,db,db),za,UNIQUE(FILTER(da,a>1)),zb,BYROW(za,LAMBDA(x,TEXTJOIN(", ",1,UNIQUE(FILTER(TEXT(db,"mm/dd/yyyy"),(da=x)*(a>1)))))),hdr,HSTACK("Names","Duplicate Dates"),VSTACK(hdr,HSTACK(za,zb)))
 
Upvote 0
Book1
ABCDEFGHIJKL
1NameDateStart TimeEnd TimeNamesDuplicate Dates
2aaaa16-01-20252:00 AM6:00 PMaaaa16-01-2025
3aaaa22-01-20254:00 AM2:00 PMnnn12-01-2025
4aaaa16-01-20255:00 PM10:00 PM
5nnn12-01-20253:00 PM10:00 PM
6aaaa22-01-20253:00 PM7:00 PM
7nnn12-01-20259:00 PM11:00 PM
8nnn25-01-202510:00 AM6:00 PM
Sheet2

Considering both Date and Timings.
In K1
Excel Formula:
=LET(da,A2:A8,db,B2:B8,dc,C2:C8,dd,D2:D8,a,MAP(da,db,dc,dd,LAMBDA(p,q,r,s,COUNTIFS(da,p,db,q,dc,"<="&s,dd,">="&r))),nm,UNIQUE(IF(a>1,da,"")),dt,UNIQUE(IF(a>1,db,"")),za,UNIQUE(FILTER(nm,nm<>"")),zb,BYROW(za,LAMBDA(Ro,TEXTJOIN(", ",1,IF(nm=Ro,TEXT(dt,"mm/dd/yyyy"),"")))),hdr,HSTACK("Names","Duplicate Dates"),VSTACK(hdr,HSTACK(za,zb)))
 
Upvote 0
an employee can't work twice in one day
Would it be any use then to just use a relatively simple Conditional Formatting formula to highlight the problem rows?

25 02 22.xlsm
AB
1EmployeeDate
2John20/02/2025
3Sarah20/02/2025
4John20/02/2025
5Mark21/02/2025
6John21/02/2025
7
8
9
10
Duplicates
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:B10Expression=COUNTIFS($A$2:$A$10,$A2,$B$2:$B$10,$B2)>1textNO
 
Upvote 0

Forum statistics

Threads
1,226,837
Messages
6,193,254
Members
453,784
Latest member
Chandni

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