Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Only Showing the Maximum of Multiple Iterations.

Only Showing the Maximum of Multiple Iterations

Written by Allen Wyatt (last updated October 9, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


Mike has three cells (A1:A3) that show results of calculations. He needs a way to determine the maximum value that has ever appeared in any of these cells, and have that value stored in cell E5. He knows how to get the maximum out of the three, but when he recalculates the worksheet, if the values in A1:A3 are less than the maximum value in E5 (based on previous determinations of the maximum in A1:A3), then E5 should not change. In other words, E5 should only change if whatever is in A1:A3 is greater than what is in E5. Mike isn't sure how to perform such a calculation.

There are two ways you can solve this issue. The first is to create a simple formula that would be placed in cell E5:

=MAX(A1:A3,E5)

The MAX function examines the various values it references and then returns the maximum out of them—exactly what is wanted. However, since this formula is being placed in cell E5 and it also references E5, it will return an error. This is because the formula creates a circular reference. Excel can handle those, but you need to make a small configuration change to do it:

  1. Display the Excel Options dialog box. (In Excel 2007 click the Office button and then click Excel Options. In Excel 2010 and later versions display the File tab of the ribbon and then click Options.)
  2. Click Formulas at the left side of the dialog box. (See Figure 1.)
  3. Figure 1. The Formulas options in the Excel Options dialog box.

  4. Make sure the Enable Iterative Calculation check box is selected.
  5. Click OK.

Now Excel will handle circular references, such as the simple formula you've put in cell E5.

The second approach is to use a macro to perform the calculation. This approach may be preferred because you may not want (for some reason) to enable circular references in your workbook. The following is actually an event handler, added to the code for the worksheet. (Easiest method: Right-click on the sheet tab, display the code window from the resulting Context menu, and add the macro to that code window.)

Private Sub Worksheet_Calculate()
    Dim dMax As Double
    dMax = Application.WorksheetFunction.Max(Range("A1:A3"))
    If dMax > Range("E5") Then
        Application.EnableEvents = False
        Range("E5") = dMax
        Application.EnableEvents = True
    End If
End Sub

The macro is triggered every time the worksheet is recalculated. It grabs the maximum of A1:A3 and compares it to what is in E5. Only if it is larger is that value then placed into E5.

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 (10916) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Only Showing the Maximum of Multiple Iterations.

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

Read-Only Embedded Fonts

If you receive a document from somebody else, you might not be able to edit it if the document contains fonts that you ...

Discover More

Using Slashed Zeroes

To reduce the chances of confusion in presenting data, some people like to use zeroes with slashes through them. If you ...

Discover More

Passing Custom Caption Labels from a Template to a Document Based on the Template

Caption labels can be useful when you are adding document elements such as tables and figures. Word allows you to create ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Transposing and Linking

Sometimes it is helpful to look at data that is rotated 90 degrees. Excel allows you to use Paste Special to transpose ...

Discover More

Generating Numeric Testing Data

Excel can be used to generate random testing data that you can use in any way you deem necessary. This tip provides ...

Discover More

Displaying a Value and a Percentage in a Single Cell

Sometimes it can be helpful to show both a numeric value and a percentage in the same cell. This can be done through ...

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 one less than 9?

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