I need to write a VBA function which checks the following:
- if the text is atleast 6 characters long;
- if the first 2 letters are capital;
- 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))
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.