代码如下,供参考:
- Sub 提取数据()
- Dim arr, brr, i As Long, mStr$, a$, b$
- With Sheet2
- arr = .Range("A1:A" & .Range("A65536").End(3).row).Value
- ReDim brr(1 To UBound(arr), 1 To 3)
- For i = 1 To UBound(arr)
- If InStr(arr(i, 1), "货发") Then
- mStr = LTrim(Split(arr(i, 1), "货发:")(1))
- If InStr(mStr, ",") Then
- a = ","
- ElseIf InStr(mStr, " ") Then
- a = " "
- Else
- a = " "
- End If
- If InStr(mStr, "省") And Mid(mStr, InStr(mStr, "省") + 1, 1) = " " Then
- b = Split(mStr, " ")(0)
- brr(i, 1) = Split(mStr, " ")(0)
- brr(i, 2) = Mid(brr(i, 1), InStrRev(brr(i, 1), " ") + 1, Len(brr(i, 1)))
- brr(i, 3) = Mid(mStr, InStrRev(mStr, " ") + 1, Len(mStr))
- brr(i, 1) = Replace(Mid(b, 1, InStrRev(b, " ") - 1), " ", "")
- Else
- brr(i, 1) = LTrim(Split(mStr, a)(0))
- brr(i, 2) = LTrim(Mid(mStr, InStr(mStr, a) + 1, Len(mStr)))
- brr(i, 3) = Empty
- End If
- End If
- Next
- For i = 1 To UBound(brr)
- If Left(brr(i, 1), 2) = "地址" Then brr(i, 1) = Mid(brr(i, 1), 3, Len(brr(i, 1)) - 2)
- If InStr(brr(i, 2), "沧州爱尔眼科医院") Then brr(i, 2) = LTrim(Replace(brr(i, 2), "沧州爱尔眼科医院", ""))
- mStr = brr(i, 2)
- If InStr(mStr, " ") Then
- brr(i, 2) = LTrim(Mid(mStr, 1, InStr(mStr, " ") - 1))
- brr(i, 3) = LTrim(Mid(mStr, InStr(mStr, " ") + 1, Len(mStr)))
- End If
- mStr = brr(i, 3)
- If VBA.IsNumeric(Left(mStr, 1)) Then
- If InStr(mStr, " ") Then brr(i, 3) = Mid(mStr, 1, InStr(mStr, " ") - 1)
- Else
- If InStr(mStr, " ") Then brr(i, 3) = Split(mStr, " ")(1)
- End If
- If brr(i, 2) Like "*[0-9]*" And Len(brr(i, 3)) = 0 Then
- mStr = brr(i, 2)
- brr(i, 2) = TQ(mStr, 1)
- brr(i, 3) = TQ(mStr, 3)
- End If
- Next
- .Range("b:d").ClearContents
- .Range("b1").Resize(UBound(brr), 3).Value = brr
- End With
- End Sub
- Function TQ(txt, Optional L = 1)
- Dim pt, i As Long, t, s
- pt = Choose(L, "[一-龥]", "[a-zA-Z]", "[0-9]", "[a-z]", "[A-Z]", "[0-9a-zA-Z]")
- For i = 1 To Len(txt)
- t = Mid(txt, i, 1)
- If t Like pt Then s = s & t
- Next
- TQ = s
- End Function
复制代码
|