98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel Training and help » Data validation
Data validation
Resolved · Low Priority · Version 365
Ben has attended:
Excel Advanced course
Data validation
Hi
my first question
I am struggling with a simple data validation rule
I would like to validate a custom code is being entered in the correct format
LLNN
L being letter
N being number
Examples TO01, BR02, XA12
what is the easiest way to do this please?
Thanks in advance
RE: data validation
Hello Ben,
Thank you for your question.
You can create a custom data validation rule in Excel to ensure that your custom code adheres to the specified format. Here’s how you can achieve this:
Select the cells where you want to apply the validation (the cells where users will input the custom codes).
Open the Data Validation dialog box:
Click the Data tab.
In the Data Tools group, click the Data Validation button.
On the Settings tab of the Data Validation dialog window:
Select Custom in the Allow box.
Enter the following formula in the Formula box:
=AND(LEN(A1)=4, ISNUMBER(VALUE(MID(A1, 3, 2))), CODE(MID(A1, 1, 1)) >= 65, CODE(MID(A1, 1, 1)) <= 90, CODE(MID(A1, 2, 1)) >= 65, CODE(MID(A1, 2, 1)) <= 90)
In the above formula, A1 represents the topmost cell of the range you want to validate.
Click OK to apply the custom data validation rule.
Here is an explanation of the formula:
LEN(A1)=4: Ensures that the code has exactly four characters.
ISNUMBER(VALUE(MID(A1, 3, 2))): Validates that the third and fourth characters are numeric.
CODE(MID(A1, 1, 1)) >= 65 and CODE(MID(A1, 1, 1)) <= 90: Checks that the first character is an uppercase letter (ASCII codes for uppercase letters).
CODE(MID(A1, 2, 1)) >= 65 and CODE(MID(A1, 2, 1)) <= 90: Verifies that the second character is also an uppercase letter.
Now, when users enter custom codes like “TO01,” “BR02,” or “XA12,” Excel will validate whether they match the specified format. If not, an error message will appear.
Feel free to adjust the formula or customize the error message as needed!
I hope this helps. Please let us know if you need further assistance.
Kind regards
Marius Barnard
STL
Training information:
See also:
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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Editing Formulas in Excel CellsAlthough people like to edit a formula in the Formula bar, you can also edit a formula in the cell. |