Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Limiting Number of Characters in a Cell.

Limiting the Number of Characters in a Cell

Written by Allen Wyatt (last updated July 30, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


2

Chris has a need to limit the number of characters that can be typed into a cell. For example, he needs to limit the input to no more than 20 characters per cell, whether they are typed or pasted into the cell. If the user tries to put in more than 20 characters, then they need to be alerted and the input disallowed. Chris wonders how he can enforce such a limitation.

Excel's Data Validation feature has a built-in way to check for the length of whatever is being entered into a cell. All you need to do is select the cell you want to limit and follow these steps:

  1. Display the Data tab of the ribbon.
  2. Click the Data Validation tool in the Data Tools group. Excel displays the Data Validation dialog box. (See Figure 1.)
  3. Figure 1. The Data Validation dialog box.

  4. Using the Allow drop-down list, choose Text Length.
  5. Using the Data drop-down list, choose Less Than.
  6. In the Maximum box, enter the value 21.
  7. Click OK.

This works fine if you are entering text into a cell, but it can be a little funky if someone is entering a numeric value. (This may not be a real problem, as entering more than 20 digits as a number is a very unusual circumstance in Excel.)

It also is a problem if you want to make sure that pasted information is checked for its length; pasting something into a cell that uses Data Validation eliminates the Data Validation on the cell. In that case you'll want to use a macro to do the length checking. You can find such a solution already at ExcelTips, in a tip entitled Setting a Length Limit on Cells.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12329) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Limiting Number of Characters in a Cell.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Printing a List of Custom Styles

You can add any number of styles to your document in order to define how you want your text to appear. If you later want ...

Discover More

Find and Replace in Headers

Using Find and Replace is something quite routine in Excel, as it easily allows you to find and replace information in ...

Discover More

Centering Your Worksheet

Got just a small amount of worksheet data to print out? It might look better on the printed page if you center it. Excel ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Deleting All Names but a Few

Want to get rid of most of the names defined in your workbook? You can either delete them one by one or use the handy ...

Discover More

Closing Up Cut Rows

When you cut and paste rows using Ctrl+X and Ctrl+V, Excel leaves empty the rows where the cut information was previously ...

Discover More

Showing Text when a Cell is Empty

Wouldn't it be great if you could have Excel display some text in a cell only when that cell is empty? Unfortuantely, ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two less than 9?

2022-08-02 13:20:33

Tomek

Also, pasting just values into the validated cell does not remove the validation setting, but validation is not triggered either.


2022-08-02 13:17:56

Tomek

There is another gotcha in the approach given in the tip.
If you enter the formula, say =B1 in a cell that has this type of data validation, say in cell B3, the validation will reject your entry if the length of text in cell B1 is greater than the limit; however, if current value in cell b1 meets the criteria, the formula will be accepted. If you change then the content of the cell B1 t exceed the length limit, the recalculation will just update the content of the cell B3 without validation, It seems that validation is not triggered by recalculation.

I know this is somewhat academic, I was just interested if the formula can be entered in the validated cell.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.