VBA:比较两列的每一行,然后剪切匹配的行并将其粘贴到别处

我有这张桌子:

ABC

4 4 X

4 1

4 0 X

4 8

4 4

4 9 X

我需要在列A和B的行中find匹配的单元格,然后剪切匹配的行并粘贴到表格下面。 数据范围是A2:C8。

在我的表中有2个匹配,所以结果应该是这样的:

4 4 X
4 4

这是我的代码:

Sub cutter() Dim cell1 As Integer, cell2 As Integer cell1 = Range("A2").Value cell2 = Range("B2").Value If cell1 = cell2 Then Sheet1.Range("A2:C2").Cut Sheet1.Range("A27:C27") End If End Sub 

它工作正常,但我需要比较每一行。 我知道我应该像这样实现循环:

 Dim rng As Range Dim row As Range Dim cell As Range Set rng = Range("A2:C8") For Each row In rng.Rows For Each cell In row.Cells ' condition Next cell Next row 

但是我不知道如何:(

帮助任何人?

提前致谢!

这段代码循环直到A中的第一个空行:

 Sub testcompare() i = 1 'start in cell 1 j = 27 'cut start in cell 27 While Not IsEmpty(Cells(i, 1)) If Cells(i, 1).Value = Cells(i, 2).Value Then Range(Cells(i, 1), Cells(i, 3)).Cut Range(Cells(j, 1), Cells(j, 3)) i = i + 1 j = j + 1 Else i = i + 1 End If Wend End Sub