Welcome :Guest

Congratulations!!!

Top 5 Contributors of the Month
Shivakumaran
hdjk11
dfefde5
hoangnganvy1993

 Home >> Code Snippets >> Validations >> Post New Resource

# Validate PAN in excel through VBA macro

Posted By:Deepika Haridas       Posted Date: September 26, 2009    Points: 10    Category: Validations    URL: http://www.dotnetspark.com

Validating PAN in excel through VBA macro.. Note : PAN CARD PATTERN - 1. START WITH ALPHABET (A-Z) 2. ALPHABET SHOULD BE 5 CHARACTER IN LENGH 3. THEN 4 DIGITS (0-9) 4. LAST CHARACTER SHOULD BE ALPHABET(A-Z) 5. All characters must be in Uppercase
`Function ValidatePAN(panentry As String) As Boolean'ValidatePAN = True'pan = Range("PAN").ValueIf Len(panentry) > 0 ThenIf Not IsNumeric(Mid(panentry, 6, 4)) Then    ValidatePAN = False    Exit FunctionEnd IfIf Not CheckAtoZ(Mid(panentry, 1, 1)) ThenValidatePAN = FalseExit FunctionEnd IfIf Not CheckAtoZ(Mid(panentry, 2, 1)) ThenValidatePAN = FalseExit FunctionEnd IfIf Not CheckAtoZ(Mid(panentry, 3, 1)) ThenValidatePAN = FalseExit FunctionEnd IfIf Not CheckAtoZ(Mid(panentry, 4, 1)) ThenValidatePAN = FalseExit FunctionEnd IfIf Not CheckAtoZ(Mid(panentry, 5, 1)) ThenValidatePAN = FalseExit FunctionEnd IfIf Not CheckAtoZ(Mid(panentry, 10, 1)) ThenValidatePAN = FalseExit FunctionEnd IfEnd IfEnd FunctionTo check the letters in PAN falls in A-ZFunction CheckAtoZ(chr1) As BooleanCheckAtoZ = TrueIf ((Asc(chr1) < 65) Or (Asc(chr1) > 90)) ThenCheckAtoZ = FalseEnd IfEnd Function`

Responses

No response found. Be the first to respond this post

Post Comment