多谢老师,我补全了代码:
Sub 提取数字()
Dim reg As Object
Dim Obj As Object
Dim i As Integer
Dim lastRow As Integer
Dim currentCol As Integer
Set reg = CreateObject("VBScript.RegExp")
With reg
.Global = True
.IgnoreCase = True
.MultiLine = True
.Pattern = "[^a-z]([0-9|/.|-]+)" '
End With
lastRow = Cells(Rows.Count, 1).End(xlUp).Row ' 获取A列的最后一行
For i = 1 To lastRow
Set Obj = reg.Execute(Cells(i, 1).Value) ' 按行提取数字
currentCol = 2 ' 从B列开始输出结果
For Each Match In Obj
If InStr(1, Match.SubMatches(0), "-") = False And Left(Match.SubMatches(0), 1) <> "." Then
Cells(i, currentCol).Value = Match.SubMatches(0) ' 将数字写入当前列
currentCol = currentCol + 1 ' 切换到下一列
End If
Next Match
Next i
End Sub