如何在Excel VBA 中使用正则表达式
1个回答
展开全部
Sub test()
Dim arr() As String
Dim oRegExp As Object
Dim oMatches As Object
Dim iNum As Integer
'定义正则对象'
Set oRegExp = CreateObject("vbscript.regexp")
Dim iRow As Integer
iRow = Sheets(1).UsedRange.Rows.Count
For ind = 1 To iRow
arr = Split(Sheets(1).Cells(ind, 1).Value, "*")
iNum = UBound(arr) - LBound(arr)
For i = 0 To iNum
With oRegExp
.Global = True
.IgnoreCase = True
.Pattern = "[0-9]+"
Set oMatches = .Execute(arr(i))
End With
Sheets(1).Cells(ind, i + 2).Value = oMatches(0)
Sheets(1).Cells(ind, 8).Value = Sheets(1).Cells(ind, 8).Value + CInt(oMatches(0))
Set oMatches = Nothing
Next
Next
End Sub
给个例子
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询