Setting an Upper Threshold for a Cell

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


Jacob wants to format a cell so that when he enters a value, if it is above a predetermined threshold, it will show the threshold. For example, if the cell is formatted so that 50 is the highest number he can enter, should he enter 60, the cell will display 50.

If all you want to do is to modify what is displayed in the cell, you could create a simple custom format in this manner:

  1. Select the cell you want to affect. (This would be the cell in which you want nothing larger than the threshold displayed.)
  2. Display the Home tab of the ribbon.
  3. Click the small icon at the lower-right corner of the Number group. Excel displays the Format Cells dialog box.
  4. Make sure the Number tab is selected. (See Figure 1.)
  5. Figure 1. The Number tab of the Format Cells dialog box.

  6. In the Category list, at the left side of the dialog box, choose Custom.
  7. In the Type box, at the left of the dialog box, enter the following format: [Red][>50]"50";0
  8. Click on OK.

This approach doesn't modify what is stored in the cell; it simply changes what is displayed in the cell—the largest value it displays is 50, and it will display it in red. The fact that the over-threshold value is still stored in the cell may cause other problems for your worksheet, which may be more trouble than it is worth.

Jacob's situation is typically handled through the use of the Data Validation capabilities of Excel. You would simply set up a rule that indicates what to do if the value in the cell is outside of whatever bounds you want:

  1. Select the cell in which you want to set your threshold.
  2. Display the Data tab of the ribbon.
  3. In the Data Tools group, click the Data Validation tool. (The Data Validation tool is in the Data Validation group if you are using Excel 2007 or Excel 2010.) Excel displays the Data Validation dialog box. (See Figure 2.)
  4. Figure 2. The Settings tab of the Data Validation dialog box.

  5. Using the Allow drop-down list, choose Whole Number. Excel changes the controls available in the dialog box.
  6. Using the Data drop-down list, selected the Less Than or Equal To option.
  7. Enter in the Maximum box the value 50.
  8. On the other tabs of the dialog box, enter an input message and an error message, if desired.
  9. Click OK.

This ensures that someone can only enter a value between 0 and 50 in the cell. If they try to enter a value outside of this range, then whatever error message you specified (step 7) is displayed and the user has the chance to enter a different value.

This approach may not fulfill Jacob's desires, however, as he would simply like to have the value in the cell be changed to the threshold value. In this case, you would need to resort to using a macro. Here's a simple one that could be used:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B7")) Is Nothing Then
        If Target > 50 Then Target = 50
    End If
End Sub

This macro is implemented as an event handler. To use it, right-click on the worksheet's tab and choose Code from the resulting Context Menu. The above macro then can be pasted into that code window. You will also need to modify which cell it is that you want the macro to pay attention to; as written, it only kicks into action if you try to enter the value into cell B7.


If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13638) 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. ...


Understanding Ascending and Descending Sorts

When you sort information, Excel follows a set pattern of how your data is organized. This tip illuminates the burning ...

Discover More

Controlling Repagination in Macros

Want to turn off document repagination while your macro does its work? Here are two approaches you can use.

Discover More

Three-Dimensional Transpositions

Excel makes it easy to transpose your data so that rows become columns and columns rows. It doesn't have a built-in ...

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)

Defeating Date Parsing when Pasting Information

Paste information directly into a worksheet, and you may be surprised that Excel makes some of the data unusable. This ...

Discover More

Inserting Different Dashes

Excel supports several types of dashes. This tip describes those different types and explains how to enter them in a cell.

Discover More

Pasting without Updating References

Do you need to paste formulas without updating the references in whatever you are pasting? You can accomplish this, ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


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 seven more than 9?

2023-03-28 09:00:54

Dave Bonin

I think I'd just include a cell (to the right of the data entry cell) with a formula that potentially modifies the user entry to a value within the acceptable range of values.

If the acceptable range were 10 to 50, I might use a formula like:
= MAX( MIN( A1, 50 ), 10 )

Keep it simple.

2019-06-06 20:56:39


Thanks for both links. That helps.

2019-06-05 10:38:56



Any of the tips in this category (Custom Formats) would be helpful to you:


2019-06-05 10:37:04

J. Woolley


2019-06-04 12:39:41


Can you provide a link to a site that discusses options and syntax for creating custom number formats? I can't find through Microsoft any guidance on what is or isn't allowed in a custom format, or the rules governing proper syntax. I often see creative solutions from you, such as in this answer, but can't find rules or guidance.

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

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.