.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Validations >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

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").Value

If Len(panentry) > 0 Then

If Not IsNumeric(Mid(panentry, 6, 4)) Then

ValidatePAN = False

Exit Function

End If

If Not CheckAtoZ(Mid(panentry, 1, 1)) Then

ValidatePAN = False

Exit Function

End If

If Not CheckAtoZ(Mid(panentry, 2, 1)) Then

ValidatePAN = False

Exit Function

End If

If Not CheckAtoZ(Mid(panentry, 3, 1)) Then

ValidatePAN = False

Exit Function

End If

If Not CheckAtoZ(Mid(panentry, 4, 1)) Then

ValidatePAN = False

Exit Function

End If

If Not CheckAtoZ(Mid(panentry, 5, 1)) Then

ValidatePAN = False

Exit Function

End If

If Not CheckAtoZ(Mid(panentry, 10, 1)) Then

ValidatePAN = False

Exit Function

End If

End If


End Function



To check the letters in PAN falls in A-Z



Function CheckAtoZ(chr1) As Boolean

CheckAtoZ = True

If ((Asc(chr1) < 65) Or (Asc(chr1) > 90)) Then

CheckAtoZ = False

End If

End Function

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend