我想比较A列和B列,并清除B列中的重复项。
Sub deleteDoublicates()
Dim i As Long
With Sheets("Tabelle1")
For i = .Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Application.IsNumber(Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Columns(1), 0)) Then
.Cells(i, "B").ClearContents
End If
Next
End With
End Sub
必须有一些完全错误的东西,因为它会删除所有内容。
您可以使用变体从application.match捕获错误。
Sub deleteDoublicates()
Dim i As Long, m as variant
With Sheets("Tabelle1")
For i = .Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
m = Application.Match(.Cells(i, "A"), Sheets("Tabelle1").Columns(1), 0)
if not iserror(m) then
.Cells(m, "B").ClearContents
End If
Next i
End With
End Sub
你自己的代码正在迭代我通过列A中的行但是莫名其妙地使用该行号来清除列B.