excel vba user form

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel VBA User Form Text Data entry Mask

Excel VBA User Form Text Data entry Mask

resolvedResolved · Medium Priority · Version 2010

Stephen has attended:
Excel VBA Intro Intermediate course

Excel VBA User Form Text Data entry Mask

Hi There

I’m working on a userform but need to add a layer of validation so that the input of data is in the following letter/number combination: AAAAA0000A

I know how to code for the length of the textbox, but how would I validate the combination above? Is this even possible?

This is what I have for the 10 digit validation that I have in place at the moment,

If Len(Me.portcode.Value) <> 10 Then
MsgBox "Portfolio Code is not 10 characters.", vbExclamation, "Payments & Transfers Error"
Me.portcode.SetFocus
Exit Sub

Any help is greatly appreciated,

RE: Excel VBA User Form Text Data entry Mask

Hi Stephen

Thanks for getting in touch. Excel VBA really lacks this Access-style input mask feature. I have an idea in code which will work but is really clumsy and can almost certainly can be improved.

If Not (WorksheetFunction.IsText(Left(Me.portcode.Value, 1))) Or _
Not (WorksheetFunction.IsText(Left(Me.portcode.Value, 2))) Or _
Not (WorksheetFunction.IsText(Left(Me.portcode.Value, 3))) Or _
Not (WorksheetFunction.IsText(Left(Me.portcode.Value, 4))) Or _
Not (WorksheetFunction.IsText(Left(Me.portcode.Value, 5))) Or _
Not (IsNumeric(Left(Me.portcode.Value, 6))) Or _
Not (IsNumeric(Left(Me.portcode.Value, 7))) Or _
Not (IsNumeric(Left(Me.portcode.Value, 8))) Or _
Not (IsNumeric(Left(Me.portcode.Value, 9))) Or _
Not (WorksheetFunction.IsText(Left(Me.portcode.Value, 10))) Then

MsgBox "Error"

End If

As I said, fairly clumsy and I'm sure a more elegant solution could be found but the principle is there.

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Wed 24 Apr 2013: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Naming and Using Constants

Constants make calculations easier so worksheets are more easily understood. Constant values also need to be given relevant and memorably names. It is also easier to change the value of a constant.

For example:
Instead of entering 17.5% in each cell when you generate a VAT amount you could name a Constant "VAT" and assigning a "0.175" value to it. To do this:

From the 'Insert' menu select 'Name', then select 'Define'.

Enter the constant

View all Excel hints and tips


Server loaded in 0.08 secs.