Textbox Alphanumeric format

p9j123

Active Member
Joined
Apr 15, 2014
Messages
288
Office Version
  1. 2013
Platform
  1. Windows
I need to restrict my textbox to a certain format.

textbox should only accept 6 numeric value and one alphabet, the format is always like shown below,

Can you assist me with this please? Either through properties or vba code.

012345A
000005B
001212X
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,
Place these two codes in your UserForm & see if will do what you want

VBA Code:
Private Sub TextBox1_Enter()
    With Me.TextBox1
        .MaxLength = 7
        .ControlTipText = "Enter 6 Numeric And 1 Alpha Value (e.g 123456A) Only"
    End With
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.TextBox1
        .Value = UCase(.Value)
        Cancel = CBool(Len(.Value) > 0 And Not .Value Like "######[A-Z]")
        .BackColor = IIf(Cancel, vbRed, vbWhite)
    End With
End Sub

Change TextBox Name as required

Merry Christmas

Dave
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top