Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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.
by Allen Wyatt
(last updated February 7, 2015)
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:
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:
Figure 1. The formulas options in the Excel Options dialog box.***Insert Figure 4 – S01816.tif
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.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10916) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Only Showing the Maximum of Multiple Iterations.
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!
It is easy to use Excel functions to sum values based on criteria you establish, unless those criteria involve the formatting ...Discover More
When processing data it is not unusual to need to round that data in some way. For instance, you may need to round a value ...Discover More
If you have a series of values in a range of cells, you may wonder how many of those values are even and how many are odd. ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.