viernes, 27 de marzo de 2015

VBA Excel: Como utilizar expresiones regulares para encontrar patrones de texto

Excelente explicacion en en este post de StackOverflow:

Private Sub simpleRegex()
    Dim strPattern As String: strPattern = "^[0-9]{1,2}"
    Dim strReplace As String: strReplace = ""
    Dim regEx As New RegExp
    Dim strInput As String
    Dim Myrange As Range

    Set Myrange = ActiveSheet.Range("A1")

    If strPattern <> "" Then
        strInput = Myrange.Value
        strReplace = ""

        With regEx
            .Global = True
            .MultiLine = True
            .IgnoreCase = False
            .Pattern = strPattern
        End With

        If regEx.Test(strInput) Then
            MsgBox (regEx.Replace(strInput, strReplace))
            MsgBox ("Not matched")
        End If
    End If
End Sub

1 comentario:

  1. They’ve obtained more than 300 video games select from|to choose from} together with over 200 slot video games, eight poker video games, 11 blackjack variations, 4 keno options, and eight roulette options. To add to this, its stay 우리카지노 casino choice has 20 stay betting options made up of various desk sport variations together with Early Payout Blackjack and Auto Roulette. Roulette is a favorite desk sport to many and Super Slots definitely has not forgotten about these players! Their collection of 14 roulette options, all which flow without a a|with no} hitch with their instant play cellular betting web site, stand out of their excellence. Most of the playing corporations are aiming for a large expansion within the form of rendering sport betting options.