本帖最后由 zjdh 于 2017-1-5 21:27 编辑
一个单元赋值给arr,不成数组!可作如下改动
Sub 提取手机号码()
arr = Range("A2:A" & Range("A65536").End(3).Row)
Set reg = CreateObject("vbscript.regexp")
reg.Pattern = "1[3578]\d{9}(?=\D|1[3578]\d{9}|$)"
reg.Global = True
If IsArray(arr) Then '是数组
For i = 1 To UBound(arr, 1)
s = arr(i, 1)
If reg.test(s) Then
Set mymatch = reg.Execute(s)
m = 2
For Each mat In mymatch
Cells(i + 1, m) = mat
m = m + 1
Next
End If
Next i
Else '非数组
Set mymatch = reg.Execute(arr)
m = 2
For Each mat In mymatch
Cells(2, m) = mat
m = m + 1
Next
End If
End Sub