- Sub test()
- Dim Dic As Object, reGxp As Object, Arr, i&, j&, tmPobj As Object, tmPsubobj As Object
- Set Dic = CreateObject("scripting.dictionary")
- Set reGxp = CreateObject("vbscript.reGexp")
- reGxp.Global = True
- reGxp.Pattern = "([^\-]+)"
- With Sheet1
- i = .Cells(.Rows.Count, "A").End(3).Row
- Arr = .[a1].Resize(i, 3)
- For i = 2 To UBound(Arr, 1)
- If Not Dic.exists(Arr(i, 1)) Then Set Dic(Arr(i, 1)) = CreateObject("scripting.dictionary")
- Set tmPobj = reGxp.Execute(Arr(i, 2))
- For Each tmPsubobj In tmPobj
- Dic(Arr(i, 1))(tmPsubobj.submatches(0) & "") = ""
- Next
- Next i
- For i = 2 To UBound(Arr, 1)
- Arr(i, 3) = Arr(i, 1) & "," & Join(Dic(Arr(i, 1)).keys, ",")
- Next i
- .[a1].Resize(UBound(Arr, 1), 3) = Arr
-
- ReDim Brr(1 To Dic.Count + 1, 1 To 1)
- Brr(1, 1) = "汇总"
- i = 1
- For Each d In Dic.keys
- i = i + 1
- Brr(i, 1) = d & "," & Join(Dic(d).keys, ",")
- Next d
- .[e1].Resize(UBound(Brr, 1), 1) = Brr
- End With
- End Sub
复制代码 |