【发布时间】:2017-10-30 22:01:00
【问题描述】:
我是 VBA 的新手。 我的问题是:
我有 3 张纸(1、2 和 3)。在sheet 1,我有A列(范围A2-end)与我想与sheet 2上的A列(范围A2-end)和D(范围D2-end)进行比较的数据。如果在 sheet 2 列 A 和 D 上未找到 sheet 1 列 A 中的值,则它应从范围 A2 开始在工作表 3 中列出 mismatched 值。
这是我所拥有的:
Sub Makro5()
Dim lastRowE As Integer
Dim lastRowF As Integer
Dim lastRowM As Integer
Dim foundTrue As Boolean
Application.ScreenUpdating = False
lastRowE = Sheets("1").Cells(Sheets("1").Rows.Count, "A2").End(xlUp).row
lastRowE = Sheets("2").Cells(Sheets("2").Rows.Count, "A2").End(xlUp).row
lastRowF = Sheets("2").Cells(Sheets("2").Rows.Count, "D2").End(xlUp).row
lastRowM = Sheets("3").Cells(Sheets("3").Rows.Count, "A2").End(xlUp).row
For i = 1 To lastRowE
foundTrue = False
For j = 1 To lastRowF
If Sheets("1").Cells(i, 1).value = Sheets("2").Cells(j, 1).value Then
foundTrue = True
and
If Sheets("1").Cells(i, 1).value = Sheets("2").Cells(j, 4).value Then
foundTrue = True
Exit For
End If
Next j
If Not foundTrue Then
Sheets("3").Rows(i).Copy Destination:= _
Sheets("3").Rows(lastRowM + 1)
lastRowM = lastRowM + 1
End If
【问题讨论】: