bugfix> vba > 投稿

;と;;VariableG5>のように、ブラケットのみでこれらを含む列DとEのすべての値を取得しようとしていますしかし、これらのテキストなしのNEW_LINE。私は括弧内のテキストを抽出する方法しか見つけませんでしたが、括弧で抽出したいのです。これは私が見つけたものです:

   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

回答 1 件
  • 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
    
    

あなたの答え