|
- Option Explicit
- Sub 拆分家庭住址()
- Dim Reg, Mat, Ma, x&, arr2(1 To 10000, 1 To 3), k&
- Dim R&, Arr, Brr, i&, a&
- Application.ScreenUpdating = False
- R = Cells(Rows.Count, 1).End(xlUp).Row
- Arr = Range("a2:a" & R)
- Set Reg = CreateObject("Vbscript.RegExp")
- With Reg
- .Global = True
- .Pattern = "([\u4e00-\u9fa5]*省)?([\u4e00-\u9fa5]*[市县])?([\u4e00-\u9fa5]*[县|市|区])"
- End With
- For i = 1 To UBound(Arr)
- Set Mat = Reg.Execute(Arr(i, 1))
- For Each Ma In Mat
- For x = 1 To 3
- arr2(i, x) = Reg.Replace(Ma, "$" & x)
- Next x
- Next Ma
- Next i
- [c:e].Clear
- [c1].Resize(1, 3) = Array("省市", "地市", "县市区")
- For a = 1 To UBound(arr2)
- If arr2(a, 1) = "" Then
- arr2(a, 1) = "山东省"
- End If
- Next a
- [c2].Resize(i, 3) = arr2
- Range("c:e").EntireColumn.AutoFit
- Range("c1:e" & R).Borders.LineStyle = xlContinuous
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|