Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Limiting Input to a Format.

Limiting Input to a Format

Written by Allen Wyatt (last updated April 27, 2019)
This tip applies to Excel 97, 2000, 2002, and 2003


As you are developing a spreadsheet, you may want to limit what users are able to put into a particular cell. For instance, you might want to make sure that entries in a cell are exactly four characters long, begin with the number 6, are followed by any digit, then by a letter, and then by any digit.

There are three ways to go about such a validation. The first, of course, is to write a macro that will check input and ensure that the entries follow the desired pattern. The way to concoct such a macro has been covered in other issues of ExcelTips.

Another method, without using macros, is to rely upon the data validation feature of Excel. If the number of valid entries is not terribly long, you might try these general steps:

  1. On a blank worksheet, construct a list of the valid entries.
  2. On the worksheet used for input, highlight the cell into which the entry will be made.
  3. Choose Validation from the Data menu. Excel displays the Data Validation dialog box. (See Figure 1.)
  4. Figure 1. The Data Validation dialog box.

  5. Using the Allow drop-down list, choose List.
  6. With the insertion point in the Source box, choose the list you put together in step 1.
  7. Click on OK.

Now, whenever someone tries to enter data that is not included in your list of acceptable values, the validation rules kick into effect and the user is forced to change the entry.

You can also use the data validation feature in a bit of a different way. If you have well-defined rules for your data entry, then you can put together a formula that describes a valid entry. The following is one such formula:

=AND((LEN(A1)=4),(LEFT(A1,1)="6"),(ISNUMBER(VALUE(
(MID(A1,2,1))))),(CODE(MID(UPPER(A1),3,1))>64),(CODE(
MID(UPPER(A1),3,1))<91),(ISNUMBER(VALUE((MID(A1,4,1))))))

Remember that this is a single formula, entered all on one line, using the following general steps:

  1. Highlight the cell into which the entry will be made. (The above formula assumes you are using cell A1. If a different cell is selected, you will need to make the appropriate reference changes to the above formula.)
  2. Choose Validation from the Data menu. Excel displays the Data Validation dialog box.
  3. Using the Allow drop-down list, choose Custom.
  4. Enter the above formula in the Formula box. (All one line, no spaces.)
  5. Click on OK.

You may get an error when you click on OK, based on the contents of A1. (Excel may try to tell you that the contents of A1 don't validate according to the rule.) This is OK; the validation rule you are setting up will come into play when someone tries to enter something in the cell.

The formula basically pulls apart the entry being made and determines if each character is within bounds. If not, then the result of the formula is FALSE, and the validation rules come into play.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2627) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Limiting Input to a Format.

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

Managing the AutoCorrect List

If you need to delete all the entries in your AutoCorrect list, the easiest way to do so is with a macro. This tip ...

Discover More

Excel Serious Sorting (Table of Contents)

Sorting data means that you organize it in whatever order you desire. Excel's sorting feature can be used in a variety of ...

Discover More

Moving a Table Column

Want to move a column in a table very easily? You can do so by using the same editing techniques you are already using.

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Adding Pop-Up Documentation to a Cell

Want to have a small help screen pop up when a user selects a particular cell? This can be done by using data validation, ...

Discover More

Single-Use Drop-Down List

Want to create an easy drop-down list? You can do so by using the data validation features of Excel.

Discover More

Setting Data Validation Input Messages

When using data validation, you might want to have Excel display a message when someone starts to enter information into ...

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 three minus 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.