|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr, crr, zrr()
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("第2时段")
- r = .Cells(.Rows.Count, 4).End(xlUp).Row
- brr = .Range("d4:l" & r)
- For i = 1 To UBound(brr)
- If Not d.exists(brr(i, 1)) Then
- Set d(brr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d(brr(i, 1))(brr(i, 2)) = i
- Next
- End With
- With Worksheets("第1时段")
- r = .Cells(.Rows.Count, 4).End(xlUp).Row
- arr = .Range("d4:u" & r)
- m = 0
- For i = 1 To UBound(arr)
- If d.exists(arr(i, 1)) Then
- If d(arr(i, 1)).exists(arr(i, 2)) Then
- m = d(arr(i, 1))(arr(i, 2))
- For j = 1 To UBound(brr, 2)
- arr(i, j + 9) = brr(m, j)
- Next
- d(arr(i, 1)).Remove (arr(i, 2))
- End If
- End If
- Next
- For Each aa In d.keys
- If d(aa).Count = 0 Then
- d.Remove (aa)
- End If
- Next
- k = 0
- xm = Empty
- For i = 1 To UBound(arr)
- If arr(i, 1) <> xm Then
- k = k + 1
- ReDim Preserve zrr(1 To 2, 1 To k)
- zrr(1, k) = i
- zrr(2, k) = i
- xm = arr(i, 1)
- Else
- zrr(2, k) = i
- End If
- Next
- ReDim crr(1 To UBound(arr) * 2, 1 To UBound(arr, 2))
- m = 0
- For k = 1 To UBound(zrr, 2)
- For i = zrr(1, k) To zrr(2, k)
- m = m + 1
- For j = 1 To UBound(arr, 2)
- crr(m, j) = arr(i, j)
- Next
- Next
- If d.exists(arr(zrr(1, k), 1)) Then
- For Each bb In d(arr(zrr(1, k), 1)).keys
- m1 = d(arr(zrr(1, k), 1))(bb)
- m = m + 1
- For j = 1 To UBound(brr, 2)
- crr(m, j + 9) = brr(m1, j)
- Next
- Next
- d.Remove (arr(zrr(1, k), 1))
- End If
- Next
- For Each aa In d.keys
- For Each bb In d(aa).keys
- m1 = d(aa)(bb)
- m = m + 1
- For j = 1 To UBound(brr, 2)
- crr(m, j + 9) = brr(m1, j)
- Next
- Next
- Next
- End With
- With Worksheets("sheet1")
- .Range("d4").Resize(m, UBound(crr, 2)) = crr
- .Select
- End With
- Application.ScreenUpdating = True
- MsgBox "数据比对完毕!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|