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

Indenting a Paragraph to the Next Tab Stop

Need to indent an entire paragraph from the left margin? It's easy to do using the tool described in this tip.

Discover More

Dynamic Worksheet Tab Names

Need a worksheet's name to change based on the contents of a cell? You'll need to rely on a macro to do the changing, but ...

Discover More

Changing the Default Text Import Delimiter

When importing text into your worksheet, Excel defaults to using a comma as a delimiter. If you would prefer a different ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Displaying a Hidden First Row

If you hide the first rows of a worksheet, you may have a hard time getting those rows visible again. Here's a simple way ...

Discover More

Getting Rid of All Rows Except the One for the Latest Date

As you use Excel to collect data over time, sometimes winnowing out the latest data can present a challenge. Here are a ...

Discover More

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
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 five more than 3?

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.