|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim reg As New RegExp
- Dim r%, i%
- Dim arr
- Dim d As New Dictionary
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- With reg
- .Global = True
- .Pattern = "外税|鼓楼|闽侯|福清|保税|音西|祥廉|融城|晋安|仓山|连江|台江"
- End With
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:c" & r)
- End With
- For i = 1 To UBound(arr)
- If reg.test(arr(i, 3)) Then
- Set mh = reg.Execute(arr(i, 3))
- d(mh(0).Value) = d(mh(0).Value) & "+" & i
- End If
- Next
- For Each ws In Worksheets
- If ws.Name <> "Sheet1" Then
- ws.Delete
- End If
- Next
- For Each aa In d.Keys
- brr = Split(Mid(d(aa), 2), "+")
- ReDim crr(1 To UBound(brr) + 1, 1 To 3)
- For i = 0 To UBound(brr)
- For j = 1 To 3
- crr(i + 1, j) = arr(brr(i), j)
- Next
- Next
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- With ws
- .Name = aa
- .Range("a1:c1") = Array("序号", "名称", "管征单位")
- .Range("a2").Resize(UBound(crr), UBound(crr, 2)) = crr
- End With
- Next
- End Sub
复制代码 |
|