比较2张纸和3张纸上的结果

时间:2013-07-15 00:26:08

标签: excel-vba vba excel

以下代码由我编辑以获得结果,但不幸的是得到它。我试图将sheet1 Col A& B与sheet2 Col A& B进行比较,并在sheet3上得到结果。请建议。

Sub ReconcileRegisters()
Dim i    As Long, _
LRa  As Long, _
LRb  As Long, _
rowx As Long

LRa = Sheets("sheet1").Range("A1:B" & Rows.Count).End(xlUp).Row
LRb = Sheets("sheet2").Range("A1:B" & Rows.Count).End(xlUp).Row
rowx = 2
Application.ScreenUpdating = False
For i = 2 To LRa
    If IsError(Application.Match(Sheets("sheet1").Range("A1:B" & i).Value, Sheets("sheet2").Range("A1:B" & LRb), 0)) Then
        Sheets("sheet3").Range("A" & rowx).Value = Sheets("sheet1").Range("A1:B" & i).Value
        rowx = rowx + 1
    End If
Next i
For i = 2 To LRb
    If IsError(Application.Match(Sheets("sheet2").Range("A1:B" & i).Value, Sheets("sheet1").Range("A1:B" & LRa), 0)) Then
        Sheets("sheet3").Range("A" & rowx).Value = Range("A1:B" & i).Value
        rowx = rowx + 1
    End If
Next i
Application.ScreenUpdating = True
MsgBox "Matching process is complete"

End Sub

1 个答案:

答案 0 :(得分:0)

如果比较两个循环,那么我认为在第二部分中需要Sheets("sheet2")

Sheets("sheet3").Range("A" & rowx).Value = Range("A1:B" & i).Value