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

Better Use of Heading Space

If your column headings are too large to work well in your worksheet, why not turn them a bit? Here's how.

Discover More

Reorganizing Data

If you need to consolidate a single column of data into multiple columns of data, you'll love this macro. It provides a ...

Discover More

Concatenating Ranges of Cells

Putting the contents of two cells together is easy. Putting together the contents of lots of cells is more involved, as ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Controlling the Automatic Copying of Formulas

When you add a new row of data to the bottom of the data of a worksheet, Excel may (or may not) copy formulas downward to ...

Discover More

Ignoring Paragraph Marks when Pasting

Paste information in a worksheet, and you may end up with Excel placing it into lots of different cells. If you want it ...

Discover More

Adjusting a Range's Starting Point

Select a range of cells, and one of those cells will always be the starting point for the range. This tip explains how to ...

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 four minus 0?

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.