Setting an Upper Threshold for a Cell

by Allen Wyatt
(last updated June 1, 2019)

4

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

Creating Tables with Specific Column Widths

Create a table and Word figures out column widths by dividing the horizontal space by the number of columns you want in ...

Discover More

Moving Subtotals

When you add subtotals to a worksheet, Excel typically places them in the same column that you are subtotaling. If you ...

Discover More

Changing the Font Size in Combo Boxes

When you add a combo box to a worksheet, Excel makes some assumptions about the best font size to use in the control. ...

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)

AutoFilling Numbers with a Trailing Period

The AutoFill tool is very handy when it comes to quickly filling cells with a sequence of values. Sometimes, however, it ...

Discover More

Changing Months in a Workbook

When you copy a worksheet and then need to make changes to information in that worksheet (such as changing month names), ...

Discover More

Moving and Copying Cells

At the very heart of editing is the ability to move and copy cells in a worksheet. Understanding the differences between ...

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}] 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 + 6?

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.