我试图查看2个不同的列,并从其中删除重复的值(如果它们都匹配)

时间:2018-11-29 17:29:14

标签: clear countif

我正在尝试查看2个不同的列,它们都具有重复项,并且只清除其中一个重复项。这是我写的,但是它在countifs行上给出了错误

Sub CleareftdupsV()


    Dim myLastRow As Long
    Dim i As Long
    Dim myCount As Long


'   Find last column in row with data
    myLastRow = Cells(Rows.Count, "B").End(xlUp).Row
    myr = Range("E:E")
    myr2 = Range("P:P")

'   Loop through range backwards
    For i = myLastRow To 1 Step -1


'   Use Countifs function to count how many cells
      myCount = Application.WorksheetFunction.CountIfs(myr, Cells(i, 5), myr2, Cells(i, 16))
'   If count greater than 1, then delete cell
        If myCount > 1 Then Cells(i, 16).ClearContents
    Next i

End Sub

此处是数据的ex

0 个答案:

没有答案