|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Option Explicit
- Sub test()
- Dim reg, ar, br(), m&, n&, k&, q&, p&, dic
- On Error Resume Next
- Set dic = CreateObject("scripting.dictionary")
- ar = Range("c6:e" & Cells(Worksheets("数据").Rows.Count, "c").End(xlUp).Row)
- Set reg = CreateObject("vbscript.regexp")
- With reg
- .Global = True
- .Pattern = "[-团内|-团外|-国内|-国外]"
- End With
- For m = LBound(ar, 1) To UBound(ar, 1)
- ar(m, 2) = reg.Replace(ar(m, 2), "")
- Next
- For n = LBound(ar, 1) To UBound(ar, 1)
- If Not dic.exists(ar(n, 2)) Then
- k = k + 1
- dic(ar(n, 2)) = ar(n, 3)
- ReDim Preserve br(1 To k)
- br(k) = ar(n, 1)
- Else
- dic(ar(n, 2)) = dic(ar(n, 2)) + ar(n, 3)
- End If
- Next n
- [g6].Resize(k, 1) = Application.WorksheetFunction.Transpose(br)
- [h6].Resize(k, 1) = Application.WorksheetFunction.Transpose(dic.keys)
- [i6].Resize(k, 1) = Application.WorksheetFunction.Transpose(dic.items)
- End Sub
复制代码 |
|