|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
- Sub 拆分家庭住址()
- Dim Reg, Mat, Ma, x&, arr2(1 To 10000, 1 To 3)
- Dim R&, Arr, Brr, i&, a&, b%
- Application.ScreenUpdating = False
- R = Cells(Rows.Count, 1).End(xlUp).Row
- Arr = Range("a2:a" & R)
- Brr = Array("天津市", "北京市", "重庆市", "上海市")
- Set Reg = CreateObject("Vbscript.RegExp")
- With Reg
- .Global = True
- .Pattern = "([\u4e00-\u9fa5]*省)?([\u4e00-\u9fa5]*[市县])?([\u4e00-\u9fa5]{1,2}[县|市|区])"
- 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(Arr)
- If arr2(a, 1) = "" Then
- If arr2(a, 3) <> "天津市" And arr2(a, 3) <> "北京市" And arr2(a, 3) <> "上海市" And arr2(a, 3) <> "重庆市" Then
- If arr2(a, 2) <> "天津市" And arr2(a, 2) <> "北京市" And arr2(a, 2) <> "上海市" And arr2(a, 2) <> "重庆市" Then
- arr2(a, 1) = "山东省"
- End If
- End If
- 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
复制代码 |
|