I have records like RF123456789, RF1234567890 etc.
I just want to match the records which are starting with 'RF' followed by exactly 9 digits of number. If it is more than 9 digit or less than 9 digit It should show Invaid. I have wrote the below code, but the problem with this is , if the number is more than 9 also it is showing valid. I understand that I have written to check only if it starts with RF and followed by 9 digits, so in case of 10 digits it is obviously matching my pattern. Is there any way I could restrict it for only 9 digits rather that 10?
Set myrange = Range("C2:C" & Rng)
For Each c In myrange
strinput = c.Value
patn = "([r|R][f|F][0-9]{9})"
If patn <> "" Then
With regex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = patn
End With
If regex.Test(strinput) Then
c.Offset(0, 5) = "Valid"
Else
c.Offset(0, 5) = "Invalid"
End If
End If
''checking Column D and E are matching or not''
If c.Offset(0, 1) <> "" Then
If c.Offset(0, 1) = c.Offset(0, 2) Then
c.Offset(0, 6) = "Matching"
Else
c.Offset(0, 6) = "Not Matching"
End If
Else
c.Offset(0, 6) = "Empty"
End If
Next