如何检查工作簿A中的数据并将其与工作簿B进行比较?
相对于工作簿B的列D和E,需要检查的工作簿A的列为AA和AE。
我将需要检查它们是否具有相同的数据,然后将其他行中的其他值复制到新工作簿中。我需要逻辑上的帮助以及如何同时检查这4列的循环。
Set input1= Workbooks("workbookA")
Set input2= Workbooks("workbookB")
LastRowAA = .Cells(.Rows.Count, "AA").End(xlUp).Row
LastRowAE = .Cells(.Rows.Count, "AE").End(xlUp).Row
LastRowD = .Cells(.Rows.Count, "D").End(xlUp).Row
LastRowE = .Cells(.Rows.Count, "E").End(xlUp).Row
For i = 1 To LastRowAA
If input1.Sheets("Sheet1").Range("AA" & i) == input2.Sheets("Sheet1").Range("D" & i ) Then
If input1.Sheets("Sheet1").Range("AE & i ) == input2.Sheets("Sheet1").Range("E" & i ) Then
blnAllMatch = False
Exit For
else
With input1
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
For Each C In .Range("F3:F" & LastRow)
wsOutput.Cells(C.Row, "I").Value = C & "" & " " & C.Offset(0, 1)
Next C
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
For Each D In .Range("E3:E" & LastRow)
wsOutput.Cells(D.Row, "H").Value = D & ""
Next D
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
For Each A In .Range("G3:E" & LastRow)
wsOutput.Cells(A.Row, "G").Value = "01"
Next A
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
For Each V In .Range("D3:D" & LastRow)
wsOutput.Cells(V.Row, "E").Value = V & ""
Next V
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
For Each z In .Range("A3:A" & LastRow)
wsOutput.Cells(z.Row, "D").Value = z & ""
End With
With input2
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
For Each y In .Range("D3:D" & LastRow)
wsOutput.Cells(y.Row, "C").Value = y & Null
Next y
End With
With Ws2
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
For Each m In .Range("B3:B" & LastRow)
wsOutput.Cells(m.Row, "B").Value = m & Null
Next m
End With
With Ws2
LastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
For Each B In .Range("F3:F" & LastRow)
wsOutput.Cells(B.Row, "F").Value = Left(Workbooks("workbookb.xls").Worksheets("Sheet1").Cells(B.Row, "G").Value, 1)
Next B
End With
End IF
谢谢
艾德里安