我一直在研究一种类似的 vba 宏。希望下面的代码有帮助!
您所需要的只是描绘并包括 1)如果可能的话,行级别比较 2)遍历数组并找到差异
** 我是
代码如下所示:
'比较代码
子比较宏()
Application.ScreenUpdating = True
Dim sheet1, sheet2, sheet4, sheet3 As Worksheet
Dim rComp, rcomp1 As Range, addy As String, addz As String
Dim iRow As Long, jCol As Long
Dim kRow As Long, lCol As Long
Dim strFileRange As String
Dim strDBRange As String
Set sheet1 = Sheets("File")
Set sheet2 = Sheets("DB")
Set sheet3 = Sheets("File(-)DB")
Set sheet4 = Sheets("DB(-)File")
sheet1.Select
Set rComp = sheet1.UsedRange
sheet2.Select
Set rcomp1 = sheet2.UsedRange
addy = rComp.Address
addz = rcomp1.Address
ary1 = rComp
ary2 = rcomp1
ary3 = sheet3.Range(addy)
ary4 = sheet4.Range(addz)
'*********File MINUS DB code goes here*********
'Step 1
'VALIDATE IF THE ROW1 OF File matches with Any of the Row in DB
'This step should include Iteration of Rows in DB range
'Step 2
'Proceed with Next row (ROW1+1 OF File) if Match Occurs
'This step contains incremental of File row & Starting comparison from First Row of DB
'Step 3
'If no Match occurs , Add the Specific Row to ary3
'This step captures the complete Mismatch record of File Row
'*********DB MINUS File code goes here*********
'Similar to the Flow of File MINUS DB
'adding the Array3 & 4 resultant Sheets
sheet3.Range(addy) = ary3
sheet4.Range(addz) = ary4
结束子