What the video covers
This guide shows how to apply Data Validation to a selected range so entries must be exactly N characters long and how to present a non-bypassable error alert.
Watch the video on YouTubeStep-by-step instructions
- Select the range
Highlight the cells or column where you want to enforce an exact character count. - Open Data Validation
Open the Data Validation dialog from the Data tab (Data Tools group) to set rules for the selected range. - Choose text length rule
In Settings, set Allow (or equivalent) to 'Text length'. Then set the condition under Data to 'equal to' if you want a single exact length. - Enter the required length
Put the exact number of characters required (for example, 5 for a 5-digit zip code) into the length/value box and confirm. - Add a Stop-style error alert
Open the Error Alert tab, set the Style to 'Stop', and write a clear Title and Message (e.g., 'Invalid Length' / 'This entry must be exactly 5 characters.'). Click OK to apply. - Test the restriction
Try entering values that are too short, too long, or include trailing spaces. Excel should block entries that do not meet the exact character count.
Watch the video
Play tutorial
Why it matters
Enforcing exact text length prevents invalid IDs, zip codes, phone numbers, and other fixed-format entries from corrupting your sheet and saves time fixing manual errors.
Check your result
Try entering a value shorter or longer than the required length — Excel should block the entry and display your custom Stop-style error message. Also test that entries with trailing spaces count toward the length.
Troubleshooting
If valid entries are still rejected, check for leading/trailing spaces (Excel counts spaces as characters). If users can paste invalid values, ensure 'Stop' is selected for the error alert; pasted values still trigger validation unless macros or external imports bypass validation.