Home > front end >  How can i write a vba code to determine if text matches parametres?
How can i write a vba code to determine if text matches parametres?

Time:01-07

I need to write a VBA function which checks the following:

  1. if the text is atleast 6 characters long;
  2. if the first 2 letters are capital;
  3. and the last 3 symbols are numbers.

Answer has to be "true" or "false"

I don't even know where to begin so i'd appreciate anything

CodePudding user response:

The below VBA function will do what you ask for.

Function Check_Text(InputText As String) As Boolean
Check_Text = (Len(InputText) >= 6 And InputText Like "[A-Z][A-Z]*###")
End Function

CodePudding user response:

Can be done without vba:

AND(LEN(A1)>=6,LEFT(A1,2)=UPPER(LEFT(A1,2)),ISNUMBER(RIGHT(A1,3)*1))

enter image description here

So LEN() checks for 6 or more, LEFT() of the first 2 characters is compared to the result of upper() to make sure the first two are uppercase, ISNUMBER() makes sure the last 3 are numerical.

  • Related