|
- Sub ddd()
- Sheets("家庭住址").Activate
- Arr = Range("a1:a" & Cells(Rows.Count, 1).End(xlUp).Row)
- ReDim brr(1 To UBound(Arr) - 1, 1 To 5)
- a = VBA.Array("北京市", "天津市", "上海市", "重庆市")
- Set Reg = CreateObject("VBScript.RegExp")
- With Reg
- .Pattern = "^(([^省]+省)|(.+自治区))?([^市]+市)?([^区县]+(市|[^小]区|县))?(.+(街道办事处|街道办|街道|[^小]镇|乡))?(.+)?"
- For i = 2 To UBound(Arr)
- theStr = Arr(i, 1)
- If theStr <> "" Then
- Set theMatches = .Execute(theStr)
- With theMatches(0)
- For j = 0 To 8
- theStr = .submatches(j)
- If j = 0 Then
- If theStr <> "" Then
- brr(i - 1, 1) = theStr
- Else
- brr(i - 1, 1) = "山东省"
- End If
- ElseIf j = 3 Then
- For k = 0 To UBound(a)
- If theStr = a(k) Then
- theProvinceYes = True
- Exit For
- End If
- Next k
- If Not theProvinceYes Then
- brr(i - 1, 2) = theStr
- Else
- brr(i - 1, 1) = theStr
- theProvinceYes = False
- End If
- ElseIf j = 4 Then brr(i - 1, 3) = theStr
- ElseIf j = 6 Then brr(i - 1, 4) = theStr
- ElseIf j = 8 Then brr(i - 1, 5) = theStr
- End If
- Next j
- End With
- End If
- Next i
- End With
- Sheets("家庭住址").Cells(2, 3).Resize(UBound(brr), UBound(brr, 2)) = brr
- Range("c:g").EntireColumn.AutoFit
- End Sub
复制代码 结合gbgbxgb 老师的代码,修改如下: |
评分
-
1
查看全部评分
-
|