|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 duquancai 于 2018-9-24 13:29 编辑
- Private Function getArr(ByVal S$) As Variant
- Dim re As Object, mt, n&, arr(), i&
- Set re = CreateObject("VBScript.Regexp")
- re.Global = True: re.Pattern = "(\S+)\s+AB\s+(\S+)\s+(\S+)"
- If re.Execute(S).Count = 0 Then Exit Function
- ReDim arr(1 To re.Execute(S).Count, 1 To 3)
- For Each mt In re.Execute(S)
- n = n + 1
- For i = 0 To 2: arr(n, i + 1) = mt.submatches(i): Next
- Next
- getArr = arr
- End Function
- Sub main()
- Dim arr, S$
- S = "姓名: 对应领导: 工单: 工单所在群" & vbCrLf
- S = S & "山依萱 AB 25137129171 3456" & vbCrLf
- S = S & "出元基 AC 13496401657 3356" & vbCrLf
- S = S & "红若芳 AD 8572498961 5346" & vbCrLf
- S = S & "贺寒松 AB 31070877046 3348" & vbCrLf
- S = S & "九彗云 AC 70157189083 2348" & vbCrLf
- S = S & "百里鹏天 AD 77571850783 3456" & vbCrLf
- S = S & "锐沈思 AB 62913168343 3356"
- arr = getArr(S)
- If Not IsArray(arr) Then Exit Sub
- Range("a2").Resize(UBound(arr), 3) = arr
- End Sub
复制代码 |
|