我在Excel中有2张纸,我正在尝试使用VBA按行进行比较。
我进行了一些搜索,但只能找到比较工作表而不是按行进行比较的帮助。
我需要对照工作表B的所有行检查工作表A的第1行,然后检查工作表A的第2行,等等,然后删除重复项,以便保留新的或更新的行。
答案 0 :(得分:0)
您需要这样的过程:
Sub cleanUp()
Dim i As Long
Dim j As Long
Dim k As Long
Dim LastRowA As Long
Dim LastRowB As Long
Dim endA As Long
Dim endB As Long
Dim rowMatch As Boolean
LastRowA = Sheets("A").UsedRange.Rows.Count
For i = 1 To LastRowA
endA = Sheets("A").Cells(i, Sheets("A").Columns.Count).End(xlToLeft).Column
LastRowB = Sheets("B").UsedRange.Rows.Count
For j = 1 To LastRowB
rowMatch = True
endB = Sheets("B").Cells(j, Sheets("B").Columns.Count).End(xlToLeft).Column
If endA <> endB Then
rowMatch = False
Else
k = 1
While rowMatch And k <= endA
If Sheets("A").Cells(i, k).Value <> Sheets("B").Cells(j, k).Value Then rowMatch = False
k = k + 1
Wend
End If
If rowMatch Then Sheets("B").Rows(j).Delete
Next j
Next i
End Sub