Prohibiting Single-Digit Entries in a Cell

Written by Allen Wyatt (last updated October 23, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

Rachel is trying to restrict a cell to only allow entries beginning with at least two digits. Thus, a single-digit entry would not be allowed, but a two-, three-, or four-digit entry would be permissible. Rachel wonders if this is possible, perhaps using Data Validation.

Yes, this can be handled through Data Validation. Assuming that you want to allow only whole numbers to be entered in the cell, you would set it up in this manner:

  1. Select the cell where the user will input their entry.
  2. Display the Data tab of the ribbon.
  3. In the Data Tools group click the Data Validation tool. Excel displays the Data Validation dialog box with the Settings tab displayed. (See Figure 1.)
  4. Figure 1. The Settings tab of the Data Validation dialog box.

  5. Using the Allow drop-down list, choose Whole Number.
  6. Using the Data drop-down list, choose Greater Than.
  7. In the Minimum box, enter the value 9. (The Minimum box is visible only after completing steps 4 and 5.)
  8. Click OK.

If your user is permitted to enter decimal values, then the steps need to be modified slightly:

  1. Select the cell where the user will input their entry.
  2. Display the Data tab of the ribbon.
  3. In the Data Tools group click the Data Validation tool. Excel displays the Data Validation dialog box with the Settings tab displayed.
  4. Using the Allow drop-down list, choose Decimal.
  5. Using the Data drop-down list, choose Greater Than or Equal To.
  6. In the Minimum box, enter the value 10. (The Minimum box is visible only after completing steps 4 and 5.)
  7. Click OK.

Either of these approaches will work fine, provided a value such as "03" isn't considered a valid two-digit entry. If this is the case, then you'll need to change entirely the way that the Data Validation is set up:

  1. Select the cell where the user will input their entry.
  2. Display the Data tab of the ribbon.
  3. In the Data Tools group click the Data Validation tool. Excel displays the Data Validation dialog box with the Settings tab displayed.
  4. Using the Allow drop-down list, choose Text Length.
  5. Using the Data drop-down list, choose Greater Than.
  6. In the Minimum box, enter the value 1.
  7. Click OK.

The drawback to allowing text entry is that, of course, a user could enter a non-sensical value, such as "ab" or "Q7." In addition, since the user is entering a text value (and it is stored in the cell as a text value), you may get funky results if you reference that cell in a formula.

You'll want to carefully consider what you are wanting the user to do when the user enters the data in the cell. You can, if necessary, enter entire formulas in the Data Validation dialog box that evaluate whatever the user enters to make sure it matches your needs. For instance, if you want the user to be able to enter anything provided the first two characters are digits, the following steps will work:

  1. Select the cell where the user will input their entry. (For the purposes of these steps, I'll assume the cell is A2.)
  2. Display the Data tab of the ribbon.
  3. In the Data Tools group click the Data Validation tool. Excel displays the Data Validation dialog box with the Settings tab displayed.
  4. Using the Allow drop-down list, choose Custom.
  5. In the Formula box, visible after completing step 4, enter the following formula. (Even though it is shown on multiple lines here, this is a single formula that should be placed in the Formula box.)
  6.       =AND(LEN(A2)>1,LEFT(A2,1)>="0",LEFT(A2,1)<="9",
          MID(A2,2,1)>="0",MID(A2,2,1)<="9")
    
  7. Click OK.

Using this scenario, the user could enter "02" or "1234" or even "73abcd." The only requirement is that the first two characters entered would be digits.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (6157) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

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

Dealing with Run-On Sentences

A common task when editing documents is to break up run-on sentences. You can make this task a little easier by using the ...

Discover More

Converting European Dates to US Dates

Those in Europe use a date format that is different than those in the US; this is not news. But what if you need to ...

Discover More

Inserting the User's Name in a Cell

Need to understand who is using a particular workbook? There are a number of ways you can find out, as discussed in this tip.

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Creating Dependent Drop-Lists

Drop-down lists are handy in an Excel worksheet, and you they can be even more handy if a selection in one drop-down ...

Discover More

Making a Drop-Down List Indicator Visible

Data validation allows you to create drop-down lists that aid data entry. If you want the indicator for the drop-down ...

Discover More

Stopping Validated Data from being Overwritten

Data Validation is a great tool to make sure that data entered in a cell meets whatever criteria you decide. Its ...

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 8 + 7?

2019-03-23 08:11:02

zeddy

You could also use a custom function to test a cell's contents.
The custom function would show TRUE if the cell contents matched your rule.
You could then use this cell's result for your Data validation.

For example, this custom function will test whether a cell's content starts with 2 digits:
Function start2digits(zCell)
If zCell Like "##*" Then start2digits = True
End Function

..as you can see, the Excel vba Like function is very versatile, and easily adapted for more intricate cell-content-testing

zeddy


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.