lrh788 发表于 2018-6-9 13:34
=LEFT(MID(A2,MIN(FIND({"区","市","县"},A2&"区市县"))+1,20),MAX(IFERROR(FIND({"区","镇","村","办","道 ...
'不会公式,找了些规律掰了一个,自己试一下看看
Option Explicit
Sub test()
Dim mark, i, j, k, t, arr, pos
t = Split("市 县 区,乡 镇 办 区 道 村", ",") '有先后次序
ReDim mark(UBound(t))
For i = 0 To UBound(mark): mark(i) = Split(t(i)): Next
arr = Range("a2:a" & Cells(Rows.Count, "a").End(xlUp).Row)
For i = 1 To UBound(arr, 1)
For j = 0 To UBound(mark(0))
If InStr(arr(i, 1), mark(0)(j)) Then Exit For
Next
If j < UBound(mark(0)) + 1 Then
t = Right(arr(i, 1), Len(arr(i, 1)) - InStr(arr(i, 1), mark(0)(j)))
pos = 0
For j = 0 To UBound(mark(1))
If InStr(t, mark(1)(j)) Then pos = j
Next
If pos > 0 Then t = Left(t, InStr(t, mark(1)(pos)))
arr(i, 1) = t
End If
Next
[g2].Resize(UBound(arr, 1)) = arr '输出g列,自己修改
End Sub |