|
先把中文的( ) 换成英文的() 然后用VBA就可以了。
- Sub Test()
- Set d = CreateObject("Scripting.Dictionary")
- For i = 3 To 8 '' 起始行是3,结束行是8
- For Each j In Split(Cells(i, 1).Value, "、")
- myItem = Val(Split(j, "(")(1))
- myCount = Val(Split(j, "(")(0))
- d(myItem) = d(myItem) + myCount
- Next j
- Next i
-
- [f1:g1] = Array("item", "count")
-
- [f2].Resize(d.Count, 1) = Application.Transpose(d.keys)
- [g2].Resize(d.Count, 1) = Application.Transpose(d.items)
-
- [f2].Resize(d.Count, 2).Sort Key1:=Range("F1"), Order1:=xlAscending, Header:=xlYes
-
- ReDim arr(1 To d.Count)
-
- For i = 1 To d.Count
- arr(i) = Cells(i + 1, "G") & "(" & Cells(i + 1, "F") & ")"
- Next
-
- Range("F:G").Clear
-
- [c4] = Join(arr, "、")
-
- End Sub
复制代码 |
|