|
本帖最后由 marchwen01 于 2017-6-18 23:44 编辑
面对这样大数据,毫无办法。两个表一共二十几万行数据,放到Access也比较不了。
只能用小办法,面对的只有小数据了。
- Option Explicit
- Sub FunMode()
- Dim arr1, arr2, iCol1, iCol2, tmp()
- Dim lRow1 As Long, lRow2 As Long, lRowTmp As Long
- Dim i As Integer, maxCol1 As Integer, maxCol2 As Integer
- Dim d As Object, dicKey
-
- iCol1 = Array(1, 2, 3, 4, 7, 8)
- iCol2 = Array(1, 2, 3, 4, 5, 9)
- arr1 = Worksheets("比较表一").Range("A1").CurrentRegion
- arr2 = Worksheets("比较表二").Range("A1").CurrentRegion
-
- maxCol1 = UBound(arr1, 2)
- maxCol2 = UBound(arr2, 2)
- ReDim tmp(1 To UBound(arr1) + UBound(arr2), 1 To maxCol1 + maxCol2)
-
- Set d = CreateObject("Scripting.Dictionary")
- For lRow2 = 2 To UBound(arr2)
- d(lRow2) = ""
- Next
-
- For i = 1 To maxCol1
- tmp(1, i) = arr1(1, i)
- Next
- For i = i To UBound(tmp, 2)
- tmp(1, i) = arr2(1, i - maxCol1)
- Next
-
- lRowTmp = 1
- For lRow1 = 2 To UBound(arr1)
- For lRow2 = 2 To UBound(arr2)
- For i = 0 To UBound(iCol1)
- If arr1(lRow1, iCol1(i)) <> arr2(lRow2, iCol2(i)) Then Exit For
- Next
- If i > UBound(iCol1) Then
- lRowTmp = lRowTmp + 1
- For i = 1 To maxCol1
- tmp(lRowTmp, i) = arr1(lRow1, i)
- Next
- For i = i To UBound(tmp, 2)
- tmp(lRowTmp, i) = arr2(lRow2, i - maxCol1)
- Next
- d.Remove lRow2
- Exit For
- End If
- Next
- If lRow2 > UBound(arr2) Then
- lRowTmp = lRowTmp + 1
- For i = 1 To maxCol1
- tmp(lRowTmp, i) = arr1(lRow1, i)
- Next
- End If
- Next
-
- For Each dicKey In d.keys
- lRowTmp = lRowTmp + 1
- For i = maxCol1 + 1 To UBound(tmp, 2)
- tmp(lRowTmp, i) = arr2(dicKey, i - maxCol1)
- Next
- Next
-
- Worksheets("代码运行落点").Range("A1").Resize(lRowTmp, UBound(tmp, 2)) = tmp
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|