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

Nudging an Equation

You can adjust where an equation is printed by moving it minute amounts in any direction.

Discover More

Anchoring Comment Boxes in Desired Locations

Want your comment boxes to appear someplace other than the right side of a cell? You may be out of luck, and here's why.

Discover More

Splitting Table Cells

When formatting tables, you can both merge and split cells. Here's a couple of ways you can easily perform the latter ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Seeing Formula Cells on Different Worksheets

Edit a cell in the Formula bar, and Excel highlights the cells referenced in that formula. If you want to see cells ...

Discover More

Creating Selections

Want a really easy way to create a selection of a group of cells? Discover how to use the Extend key to make this task ...

Discover More

Defeating Date Parsing when Pasting Information

Paste information directly into a worksheet, and you may be surprised that Excel makes some of the data unusable. This ...

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 more 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.