|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a3:c" & r)
- For i = 1 To UBound(arr)
- If Left(arr(i, 1), 1) = "半" Then
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 1))(i) = ""
- End If
- Next
- ReDim brr(1 To 1000, 1 To 4)
- m = 0
- For i = 1 To UBound(arr)
- If Left(arr(i, 1), 1) <> "半" Then
- If Not d.exists(arr(i, 2)) Then
- m = m + 1
- brr(m, 1) = arr(i, 1)
- brr(m, 2) = arr(i, 2)
- brr(m, 3) = arr(i, 2)
- brr(m, 4) = arr(i, 3)
- Else
- For Each bb In d(arr(i, 2)).keys
- m = m + 1
- brr(m, 1) = arr(i, 1)
- brr(m, 2) = arr(i, 2)
- brr(m, 3) = arr(bb, 2)
- brr(m, 4) = arr(i, 3) * arr(bb, 3)
- Next
- End If
- End If
- Next
- .Range("e3").Resize(m, UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|