|
两个工作簿的同名表进行数据核对,现在只有一个表G21核对是对的,请大神给我修改代码,按照sheet3列给出的表名称核对同名表数据,其他没列出的表不需要核对数据,谢谢- Sub lqxs2()
- Dim Arr, myPath$, nm$, I&, Brr, aa, r, r1, l, l1, y&, j&, n&
- On Error Resume Next
- myPath = ThisWorkbook.Path & "\B.xlsx"
- ReDim Brr(1 To Sheets.Count)
- With GetObject(myPath)
- On Error Resume Next
- 'For x = 1 To [b65536].End(3).Row
- For I = 1 To .Sheets.Count
- Z = Cells(I, 2)
- 'For I = 1 To .Sheets.Count
- .Sheets(I).Name = Z
-
- Brr(I) = .Sheets(Z).UsedRange
- Next
- 'Next
- .Close False
- End With
- For I = 1 To Sheets.Count
- 'For x = 1 To [b65536].End(3).Row
- Z = Cells(I, 2)
- Sheets(I).Name = Z
- 'For I = Sheets(x).Name To Sheets.Count
- nm = Sheets(Z).Name: n = 0
- aa = nm & "表格中有以下不同的单元格:" & vbCrLf
- Arr = Sheets(Z).UsedRange
- r = UBound(Arr): r1 = UBound(Brr(I))
- l = UBound(Arr, 2): l1 = UBound(Brr(I), 2)
- If r >= r1 Then m = r Else m = r1
- If l >= l1 Then c = l Else c = l1
- For j = 1 To m
- For y = 1 To c
- If Arr(j, y) <> Brr(I)(j, y) Then
- n = n + 1
- aa = aa & Cells(j, y).Address(0, 0) & vbCrLf
- End If
- Next
- Next
-
- If n > 0 Then
- MsgBox aa
- Else
- MsgBox nm & "表格没有不同。"
- End If
- Next
- 'Next
- End Sub
复制代码
|
|