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

Performing Calculations while Filtering

The advanced filtering capabilities of Excel allow you to easily perform comparisons and calculations while doing the ...

Discover More

Controlling the Behavior of the Mouse Wheel

The mouse wheel, by default, controls scrolling vertically through your worksheet. If you don't want the wheel to control ...

Discover More

Noting Moved Words and Phrases in Markup

The Track Changes tool can be very helpful in keeping track of the edits in a document. If you want to track when you ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Mouse Scroll Wheel Doesn't Work when Editing Formulas

Using your mouse to select cells for inclusion in a formula can be an exercise in futility on some systems. Here's why ...

Discover More

Identifying Duplicates

Do you need to flag duplicate values in your data? This tip shows three different ways you can do the flagging you need.

Discover More

Automatically Moving from Cell to Cell when Entering Data

As you enter data in a worksheet, you may want to have Excel automatically move from cell to cell based on the length of ...

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 nine minus 1?

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.