我试图获取D列和E列中的所有值,其中只包含括号 - 例如;;;; VariableG5> 但没有这些文本NEW_LINE.I只发现如何提取括号之间的文本,但我想用括号提取它。这是我发现的:
Public Sub My_Split()
Dim z As Variant
z = Split(Replace(Join(Filter(Split(Replace(Replace(Selection.Value, "<" , ">")
Selection.Offset(0, 1).Resize(, UBound(z) + 1) = z
End Sub
答案 0 :(得分:0)
Sub simpleRegex()
Dim strPattern As String: strPattern = " <([a-z] | [A-Z] | [0-9] | \. | - | _)+>"
Dim Match As Object
Dim matches As Object
Dim regex As Object
Set regex = CreateObject("VBScript.RegExp")
Dim strInput As String
Dim Myrange As Range
Set Myrange = ActiveSheet.Range("D8:D10")
For Each cell In Myrange
If strPattern <> "" Then
strInput = cell.Value
With regex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regex.Test(strInput) Then
Set matches = regex.Execute(strInput)
For Each Match In matches
MsgBox (Match.Value) 'A workaround I found to see if my pattern
'worked but I need to print Match.value
'in a column so this wont do
Next
Else
MsgBox ("Not matched")
End If
End If
Next
End Sub