Originally Posted by
Rick Rothstein
This should account for the requirement you posted about...
Code:
Function IsPAN(S As String) As Boolean
IsPAN = S Like "[A-Za-z][A-Za-z][A-Za-z][ABFGHJLPTabfghjlpt][A-Za-z]####[A-Za-z]"
End Function
Hi
I wanted to function like this..
Code:
Function ISPAN(inData As String)
Dim i As Integer
Dim Result As String
If Len(inData) <> 10 Then
ISPAN = "Total Character is " & Len(inData)
Exit Function
End If
If Mid(UCase(inData), 1, 1) Like "[A-Z]" Then
r1 = ""
Else
r1 = "Char1 is not Text,"
End If
If Mid(UCase(inData), 2, 1) Like "[A-Z]" Then
r2 = ""
Else
r2 = "Char2 is not Text,"
End If
If Mid(UCase(inData), 3, 1) Like "[A-Z]" Then
r3 = ""
Else
r3 = "Char3 is not Text,"
End If
If Mid(UCase(inData), 4, 1) Like "[P]" Then
r4 = ""
Else
r4 = "Char4 Should be P"
End If
If Mid(UCase(inData), 5, 1) Like "[A-Z]" Then
r5 = ""
Else
r5 = "Char5 is not Text,"
End If
If Mid(UCase(inData), 6, 1) Like "#" Then
r6 = ""
Else
r6 = "Char6 is not Number,"
End If
If Mid(UCase(inData), 7, 1) Like "#" Then
r7 = ""
Else
r7 = "Char7 is not Number,"
End If
If Mid(UCase(inData), 8, 1) Like "#" Then
r8 = ""
Else
r8 = "Char8 is not Number,"
End If
If Mid(UCase(inData), 9, 1) Like "#" Then
r9 = ""
Else
r9 = "Char9 is not Number,"
End If
If Mid(UCase(inData), 10, 1) Like "[A-Z]" Then
r10 = ""
Else
r10 = "Char10 is not Text,"
End If
Result = r1 & r2 & r3 & r4 & r5 & r6 & r7 & r8 & r9 & r10
If Right(Result, 1) = "," Then
Result = Left(Result, Len(Result) - 1)
End If
If Result = "" Then
ISPAN = "OK"
Else
ISPAN = Result
End If
End Function
This works fine but it is very lengthy can we shortn same by looping, I am not expert in VBA
Thanks for all support.
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
Bookmarks