May 29, 2019

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
MsgBox “Invalid PAN entry”
Exit Sub
End If
End Sub

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.

Comments are closed.