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:
Figure 1. The Formulas options in the Excel Options dialog box.
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:
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 Office 365. You can find a version of this tip for the older menu interface of Excel here: Only Showing the Maximum of Multiple Iterations.
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!
Need to know the directory (folder) in which a workbook was saved? You can create a formula that will return this ...
Discover MoreIf your worksheet formulas seem to go on forever, here's a handy way to make them more understandable. (All you need to ...
Discover MoreIf you have circular references in a workbook, you may see an error message appear when you first open that workbook. If ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2019-02-25 18:06:22
Garry
Hello Steve,
Apologies for this very late reply. Thank you for the water storage formula you sent on 2 Feb. It works a treat.
Kind Regards,
Garry
2019-02-07 04:26:17
Garry,
Not entirely sure this exactly what you are after and it may cause issues if you copy it down as you are referencing the answer from previous calculation - unless that's what you need to do.
Using your cell references,
=IF(AND(J8>20,K7+J8*0.0175<14),K7+J8*0.0175,IF((K7+(J8*(K$2+17.5)-K$2*20)/1000)<14,K7+(J8*(K$2+17.5)-K$2*20)/1000,14))
(see Figure 1 below)
Figure 1. Formula example
2019-02-06 07:17:40
Garry
Hello,I am wanting to put a maximum value on a number calculated from an 'IF' formula for a water storage calculation. The formula is (for location K8), K8=IF(J8>20,K7+J8*0.0175,K7+(J8*(K$2+17.5)-K$2*20)/1000). I want K8 (and subsequent locations down the column) to not exceed 14, but the formula to remain in tact. I understand that this would constitute a circular reference which doesn't work in excel. That's OK, but I am simply wanting to impose a maximum value on each progressive column location. How might I be able to do this? Thanks, Garry
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2021 Sharon Parq Associates, Inc.
Comments