Search code examples
excelvbastringletter

Is there an easy way to check if the string starts with letters (any 4 letters)?


is there a way to check if the string begins with any 4 letters. I am looking for something like this:

If string like "####*" then
'DO STUFF
end if

"#" is for digits, I need the same thing but for letters only. Can this be done without regEx?


Solution

  • I don't know a way to do this without using regular expressions. We can try using regex Test along with the pattern ^[A-Z]{4}.*$:

    Dim input As String
    Dim regex As Object
    Set regex = New RegExp
    
    regex.Pattern = "^[A-Z]{4}.*$"
    input = "ABCD blah"
    
    If regex.Test(input) Then
        'DO STUFF
    End If