score:3

you can use regular expressions. regular expressions are used for pattern matching. to use in excel follow these steps.

step 1: add vba reference to "microsoft vbscript regular expressions 5.5"

  • select "developer" tab (i don't have this tab what do i do?)
  • select "visual basic" icon from 'code' ribbon section
  • in "microsoft visual basic for applications" window select "tools" from the top menu.
  • select "references"
  • check the box next to "microsoft vbscript regular expressions 5.5" to include in your workbook.
  • click "ok"

example

private sub regex()

    dim userinput as string
    userinput = "{{heading1} + {{heading2} * {heading3}}}"

    dim pattern as string
    pattern = "\{([a-za-z0-9]*)\}"

    dim regex as new regexp

    with regex
        .global = true
        .multiline = true
        .ignorecase = false
        .pattern = pattern
    end with

    dim matches
    set matches = regex.execute(userinput)

    for each match in matches
        debug.print "match found at position " & match.firstindex
        debug.print "match value is '" & match.value & "'"
        debug.print ""
    next

end sub

Related Query

More Query from same tag