|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d1 As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- Set d3 = CreateObject("scripting.dictionary")
- With Worksheets("齐套明细")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:g" & r)
- For i = 1 To UBound(arr)
- If Not d1(arr(i, 2)) Then
- ReDim brr(1 To 2)
- brr(1) = arr(i, 4)
- Else
- brr = d1(arr(i, 2))
- End If
- brr(2) = brr(2) + arr(i, 6)
- d1(arr(i, 2)) = brr
- Next
- End With
- With Worksheets("核心网和服务器计划组分类")
- r = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- arr = .Range("a2:e" & r)
- For j = 1 To 4 Step 3
- For i = 1 To UBound(arr)
- If Len(arr(i, j)) <> 0 Then
- d2(arr(i, j + 1)) = arr(i, j)
- End If
- Next
- Next
- End With
- With Worksheets("分类")
- r = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- For j = 1 To UBound(arr, 2) Step 3
- For i = 2 To UBound(arr)
- If Len(arr(i, j)) <> 0 Then
- If d1.exists(arr(i, j)) Then
- crr = d1(arr(i, j))
- xm = ""
- If arr(1, j) <> "核心网及服务器代码" Then
- xm = arr(1, j)
- Else
- If d2.exists(crr(1)) Then
- xm = d2(crr(1))
- End If
- End If
- If xm <> "" Then
- If Not d.exists(xm) Then
- Set d(xm) = CreateObject("scripting.dictionary")
- End If
- d(xm)(arr(i, j + 1)) = d(xm)(arr(i, j + 1)) + crr(2)
- End If
- End If
- End If
- Next
- Next
- End With
- With Worksheets("汇总")
- .Cells.ClearContents
- n = 1
- For Each aa In d.keys
- .Cells(1, n) = aa & "机型"
- .Cells(1, n + 1) = "数量"
- .Cells(2, n).Resize(d(aa).Count, 2) = Application.Transpose(Array(d(aa).keys, d(aa).items))
- n = n + 3
- Next
- End With
- End Sub
复制代码 |
|