Validate Alphanumeric Data

How to validate an alphanumeric data entry like a permanent account number (PAN) in a text-box on a user-from with vba quickly and easily. A PAN has the following characteristics:

First Three Digits Alphabetic series running from AAA to ZZZ
Fourth Digit Status (I.e. P For Personal, C for Corporate, F for Firm, H for Hindu Undivided Family Etc.)
Fifth Digit First character of assessee’s Last Name/ Surname
Next 4 Digits Sequential Number running from 0001 to 9999
Last Digit Alphabetic Check digit

Watch the video below:

Here’s the complete VBA code to validate an alphanumeric data entry in a text-box quickly<

Private Sub CommandButton1_Click()
If TextBox1.Text Like “[A-Za-z][A-Za-z][A-Za-z][ABFGHJLPTabfghjlpt][A-Za-z]####[A-Za-z]” Then
MsgBox “Valid PAN entry”
Range(“A2”) = TextBox1.Text
Else
MsgBox “Invalid PAN entry”
Exit Sub
End If
End Sub

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

One thought on “Validate Alphanumeric Data”

  1. Respected sir,
    Let me just start this message by thanking you for all the noble work you have been doing for learner’s like us. Your work of automation has really simplified my work and saved more of my productive time.
    Need a help from you sir. At my work in a day I get around 100 to 200 pdf files which needs to be merged in a set of 3 pdf files into one which really takes a lot of my productive time. So I was thinking if you could possibly help me with a macro for merging the same in one go. For instance I will be saving pdf files in the format of 1.pdf 2.pdf 3.pdf 4.pdf 5.pdf 6.pdf. Now here the macro would work on the constrain of 3 that I provide to it. And it would merge that 1.pdf+2.pdf+3.pdf and give me and output in other folder as 1.pdf/test1.pdf and on the loop it will merge 4.pdf+5.pdf+6.pdf and give output as 2.pdf/test2.pdf and so on it will run the process until the last set is completed and on completion it would give a message box of completion.
    Is this possible with excel via sir. Really looking forward to your response sir. Would be really very Greatfull to you for this as it would really save a lot of my productive time sir. Please please help me in this.
    I really wanna thank you again for starting this page you have no idea sir how helpful your methods are to us. Awaiting your response sir.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.