Keeping a Max Value in a Cell

by Allen Wyatt
(last updated May 15, 2021)


Eric has a worksheet that updates portfolio values every minute. Say cell B1 is the total value at the current time. This sum updates once per minute as the data on which it is based is updated. Eric would like to have cell B2 show the maximum value that B1 has ever reached. In other words, B2 will only change when the value in B1 goes higher than what is currently in cell B2.

This could be done with a simple iterative formula in cell B2, like this:


If you don't have iterative calculations enabled, then you will get an error when you first enter this formula. For the formula to work, you will need to allow circular references by following these steps:

  1. Display the File tab of the ribbon and then click Options. Excel displays the Excel Options dialog box.
  2. At the left side of the dialog box, choose Formulas. (See Figure 1.)
  3. Figure 1. The Formulas tab of the Excel Options dialog box.

  4. Make sure the Enable Iterative Calculation check box is selected.
  5. Set the Maximum Iterations value to something low (such as 1 or 2).
  6. Set the Maximum Change value to something large enough to cover whatever maximum change you may expect to see between what is in cell B2 and what is summed in cell B1. (A good, safe value might be something like 1000.)
  7. Click OK.

If you are using Excel 2007, the steps are a bit different—choose Tools | Options | Calculation tab and make sure the Iteration check box is selected.

The formula will work just fine, provided cell B1 never displays an error. If you think that, at some point, B1 might contain an error, then you could modify your formula in cell B2 just a bit:


The result is that B2 is updated only if the value in B1 is not an error and it is greater than what is currently in B2.

If you cannot use iterative calculations for some reason (perhaps because of other formulas in your worksheet), then you may want to use a macro to do the updating of cell B2. If your worksheet data is already being updated via macro, then you could simply modify the macro to recalculate the worksheet and then compare what is in B1 to B2. If B1 is greater, then the macro can update the value in B2.

If your data is not being updated by a macro, then you could create an event handler to do the updating. The following should be placed in the worksheet's code window:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$1" Then
        If Target.Value > Range("B2").Value Then
            Application.EnableEvents = False
            Range("B2").Value = Target.Value
            Application.EnableEvents = True
        End If
    End If
End Sub

Every time cell B1 changes, the macro compares B1 to B2. If it is greater, then events are temporarily turned off and the value in B2 is updated.

Note that this event handler will be triggered if cell B1 is changed explicitly (someone enters a new value in B1) or implicitly (the value in B1 is updated when the worksheet is recalculated). It will not be triggered if the value in B1 is updated via macro or if it is updated by virtue of being linked to a source external to the worksheet. In those cases you might need to modify your comparison macro to run via timer or, perhaps, simply use the circular comparison formula described earlier.


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 (13859) 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. ...


Distributing Table Rows Evenly

If you've adjusted the height of your table and the rows within the table, you might want to later return all those rows ...

Discover More

Fonts Unavailable in Word

If you have some fonts that don't show up as available in Word, their exclusion can be confusing. Here's a discussion of ...

Discover More

Determining a Format's Currency Symbol

Excel allows you to format numeric values in many different ways, including as currency. If you want to determine, in a ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Calculating the Distance between Points

Want to figure out how far it is between two points on the globe? If you know the points by latitude and longitude, you ...

Discover More

Adding Dashes between Letters

When processing some text data, you may need to perform some esoteric function, such as adding dashes between letters. ...

Discover More

Checking for Proper Entry of Array Formulas

Excel allows you to enter two different types of formulas in a cell: A regular formula or an array formula. If you need ...

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}] 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 less than 3?

2021-05-15 10:19:08


Contrary to what is stated in the tip, the macro given will not run on recalculation. Worksheet_Change is not triggered by recalculation, you have to use Worksheet_Calculate event. This makes it complicated as the Worksheet_Calculate event does not have a target. may be Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range) could be used.

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.