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


5

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.

Note:

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. ...

MORE FROM ALLEN

Inserting the Subject in Your Document

One of the properties you can specify for a document is a subject. You can then use a field code to insert this subject, ...

Discover More

Listing Combinations

You can easily use the COMBIN worksheet function to determine the number of combinations that can be made from a given ...

Discover More

Formatting Lots of Tables

Do you need a quick way to format your tables? Believe it or not, there are several tools you can use from Word's arsenal ...

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)

Getting Help when Entering Functions

Need a quick memory jog when entering a worksheet function? Here's a shortcut that will be invaluable.

Discover More

Splitting Cells to Individual Columns

When you are working with data created by other systems or other people, you often need to convert the data into ...

Discover More

Copying Cells to Fill a Range

Excel provides two really helpful shortcuts you can use to fill a range of cells, either horizontally or vertically. ...

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 4 + 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

StevenM

Thanks for both links. That helps.


2019-06-05 10:38:56

Allen

StevenM:

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

https://excelribbon.tips.net/C0752_Custom_Formats.html

-Allen


2019-06-05 10:37:04

J. Woolley

@StevenM

https://exceljet.net/custom-number-formats


2019-06-04 12:39:41

StevenM

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
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.