View Single Post
 
Old 02-01-2018, 02:34 AM
jodecaesteker jodecaesteker is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2018
Posts: 6
jodecaesteker is on a distinguished road
Default

Found it myself!

Code:
 
Sub check_format()
Dim ok As Boolean
Dim str As String
 
'select the cell to check and run the macro - "ok" is the boolean that will...
'...determine whether the pattern is matching. It is set to true if the cell matches...
'...one of the allowed patterns.
 
str = Selection.Value
ok = False
 
Select Case True
    Case str Like "##[.]": ok = True
    Case str Like "##[.]##[.]": ok = True
    Case str Like "##[.]##[.]##[.]": ok = True
    Case str Like "##[.]##[.]##[.]##[.]": ok = True
End Select
 
If ok = False Then
    MsgBox ("Wrong pattern!")
Else
    MsgBox ("Pattern is ok!")
End If
 
End Sub
As said, I'm new to vba and my coding might not be as efficient as it could be.
I do like the "case" method as it is very readable and easy/convenient to add or delete new patterns.

Cheers!
Reply With Quote