简体   繁体   English

根据另一列中的日期删除一列中的重复项

[英]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.我有一个包含两列的 Excel 电子表格:A 列包含名称列表,B 列包含日期。

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?为什么不使用标准的Remove duplicates功能?

在此处输入图片说明

If you decide to use VBA try:如果您决定使用 VBA,请尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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