|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("订单所需组件")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:b" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 1))(arr(i, 2)) = Empty
- Next
- End With
- With Worksheets("订单")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:c" & r)
- End With
- ReDim brr(1 To 1000, 1 To 3)
- m = 0
- For i = 1 To UBound(arr)
- m = m + 1
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(i, j)
- Next
- If d.exists(arr(i, 1)) Then
- For Each bb In d(arr(i, 1)).keys
- m = m + 1
- brr(m, 1) = arr(i, 1)
- brr(m, 2) = bb
- brr(m, 3) = arr(i, 3)
- Next
- End If
- Next
- With Worksheets("想要得到的结果")
- .UsedRange.Offset(1, 0).Clear
- .Range("a2").Resize(m, UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|