|
楼主 |
发表于 2018-9-22 22:47
|
显示全部楼层
经过3天调试成功,哈哈,备份- Sub lqxs4()
- Dim Arr, myPath$, nm$, I&, Brr, aa, r, r1, l, l1, y&, j&, n&
- Dim d, k, t, wk1 As Workbook, wk2 As Workbook, Crr
- Set d = CreateObject("Scripting.Dictionary")
- Dim Sht As Worksheet
- Set wk1 = ThisWorkbook
- For Each Sht In Sheets
- d(Sht.Name) = ""
- Next
- 'Brr = Sheet3.[b1].CurrentRegion
- Brr = Sheet3.Range([b1], [B65536].End(3))
- 'myPath = ThisWorkbook.Path & "\b.xlsx"
- myPath = ("C:\Users\Administrator\Desktop\测试\同名表多表格数据的核对\b.xlsx")
- With GetObject(myPath)
- 'With CreateObject("Scripting.FileSystemObject")
- ' Set wk2 = .GetFolder(ThisWorkbook.Path & "\b.xlsx")
- Set wk2 = Workbooks("b.xlsx")
- 'Set wk2 = ThisWorkbook
- ' Set wk2 = Workbooks(myPath)
-
-
- ' Set wk2 = Workbooks("B.xlsx").Sheets(3).[B65536].End(xlUp).Row + 1
-
- For I = 1 To UBound(Brr)
- s = Brr(I, 1) & "表格中有以下不同的单元格:" & vbCrLf
- If d.exists(wk2.Sheets(I).Name) Then
- Arr = wk1.Sheets(Brr(I, 1)).UsedRange
- Crr = wk2.Sheets(Brr(I, 1)).UsedRange
- For X = 1 To UBound(Arr)
- For y = 1 To UBound(Arr, 2)
-
- ' If Arr(x, y) <> Crr(x, y) Then s = s & x & "|" & y & vbCrLf
-
- If Arr(X, y) <> Crr(X, y) Then s = s & Cells(X, y).Address(0, 0) & vbCrLf
-
- Next
- Next
- 'If InStr(s, "|") <> 0 Then MsgBox s
- If s <> 0 Then MsgBox s
- Else
- MsgBox s & "表格没有不同。"
-
- End If
- Next
- .Close False
- End With
- End Sub
复制代码 |
|