简体   繁体   中英

Remove duplicates in one column based on a date in another column

I have an excel spreadsheet with two columns: Column A contains a list of names and Column B contains dates.

I want to get rid of duplicate entries based on dates. This is an example

A     B

John  01/03/2020

John  01/03/2020 

Bob   01/03/2020

John  02/03/2020

Bob   02/03/2020

Bob   02/03/2020

I want to remove duplicates that have the same date, so the final result should be:

A     B

John  01/03/2020

Bob   01/03/2020

John  02/03/2020

Bob   02/03/2020

Why aren't you using the standard Remove duplicates functionality?

在此处输入图片说明

If you decide to use VBA try:

Sub test()

    Dim i As Long, y As Long, Lastrow As Long
    Dim strName As String
    Dim dtDate As Date

    With ThisWorkbook.Worksheets("Sheet1")
        Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row

        For i = Lastrow To 1 Step -1

            For y = i - 1 To 1 Step -1
                If (.Range("A" & i).Value = .Range("A" & y).Value) And (.Range("B" & i).Value = .Range("B" & y).Value) Then
                    .Rows(i).EntireRow.Delete
                End If

            Next y

        Next i

    End With

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM