|
Sub 数据比对()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Dim arr()
lj = ThisWorkbook.Path & "\"
f = Dir(lj & "宿舍-清单定额汇总表.xls*")
If f = "" Then MsgBox "找不到宿舍-清单定额汇总表": End
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:g" & r)
End With
wb.Close False
ReDim arr(1 To 100000, 1 To 17)
For i = 3 To UBound(ar)
If Trim(ar(i, 1)) = "" Then ar(i, 1) = ar(i - 1, 1)
If Trim(ar(i, 1)) <> "" Then
n = n + 1
For j = 1 To UBound(ar, 2)
arr(n, j + 2) = ar(i, j)
Next j
arr(n, 2) = "第" & i & "行"
zd = ar(i, 3) & "|" & ar(i, 6)
d(zd) = n
End If
Next i
Set f = Nothing
f = Dir(lj & "宿舍-清单汇总表.xls*")
If f = "" Then MsgBox "找不到宿舍-清单汇总表": End
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:g" & r)
End With
wb.Close False
For i = 3 To UBound(ar)
If Trim(ar(i, 1)) = "" Then ar(i, 1) = ar(i - 1, 1)
If Trim(ar(i, 1)) <> "" Then
zd = ar(i, 3) & "|" & ar(i, 6)
xh = d(zd)
If xh <> "" Then
For j = 1 To UBound(ar, 2)
arr(xh, j + 10) = ar(i, j)
Next j
arr(xh, 10) = "第" & i & "行"
Else
n = n + 1
For j = 1 To UBound(ar, 2)
arr(n, j + 10) = ar(i, j)
Next j
arr(n, 10) = "第" & i & "行"
arr(n, 1) = "新增行"
End If
End If
Next i
For i = 1 To n
If Trim(arr(i, 2)) <> "" And Trim(arr(i, 10)) = "" Then
arr(i, 1) = "删除行"
ElseIf Trim(arr(i, 2)) = "" And Trim(arr(i, 10)) <> "" Then
arr(i, 1) = "新增行"
ElseIf Trim(arr(i, 2)) <> "" And Trim(arr(i, 10)) <> "" Then
zd = ""
For j = 3 To 9
If zd = "" Then
zd = arr(i, j)
Else
zd = zd & "|" & arr(i, j)
End If
Next j
zf = ""
For j = 11 To 17
If zf = "" Then
zd = arr(i, j)
Else
zf = zf & "|" & arr(i, j)
End If
Next j
If zd <> zf Then
arr(i, 1) = "修改行"
Else
arr(i, 1) = ""
End If
End If
Next i
With Sheets("对比")
.UsedRange.Offset(2).Borders.LineStyle = 0
.UsedRange.Offset(2) = Empty
.[a3].Resize(n, UBound(arr, 2)) = arr
.[a3].Resize(n, UBound(arr, 2)).Borders.LineStyle = 1
End With
Set f = Nothing
Set d = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|