我一直在研究一个宏,如果表的 A 列中的值与另一个单独的 B 列中的任何值都不匹配,则删除表中的行。目前,我的代码没有正确删除最后一行,并且我终其一生都无法弄清楚为什么。
这是我当前的代码:
Sub Stuff()
Dim rCell As Range, ColumnA As Range, ColumnB As Range
Dim rowPoint As Integer
Set ColumnA = ActiveWorkbook.Worksheets("Sheet1").Range("Table2[Column1]")
Set ColumnB = ActiveWorkbook.Worksheets("Sheet1").Range("Table1")
rowPoint = ColumnA.Count
On Error Resume Next
For i = rowPoint To 1 Step -1
For Each rCell In ColumnA
If Application.CountIf(ColumnB, rCell.Value) = 0 Then rCell.Rows.Delete
Next rCell
Next i
End Sub