
Tips.Net > ExcelTips Home > Formulas > Determining "Highest Since" or "Lowest Since"
Summary: When compiling statistics on a collection of data points, you may want to know whether a particular value is the “highest since” or “lowest since” when compared to the preceding data in the collection. You can figure out this information with either a formula or a macro, as described in this tip. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)
Alex routinely analyzes the latest building industry data, and needs to write articles about the data. Frequently he needs to highlight some new piece of data, such as "industrial building construction was the lowest since August 2005." Alex wondered if there was a way to automate this type of highlighting; if column A contains the month and year and column B contains the values for those periods, Alex would like a formula in column C that indicates "this value is the highest since April 2005" or "this value is the lowest since November 2002."
Assuming that the month and year listed in column A is really an Excel date value (and not text), you can easily create a formula to return the desired information. If you have row 1 occupied with headings for your columns, enter the following in cell C2:
=IF(ROW(B2)=2,"",IF(B2>MAX($B$1:B1), "this value is the highest since " & TEXT(INDEX($A$1:A1,MATCH(MAX( $B$1:B1),$B$1:B1,0)), "mmmm yyyy"), IF(B2<MIN($B$1:B1), "this value is the lowest since " & TEXT(INDEX($A$1:A1, MATCH(MIN($B$1:B1),$B$1:B1,0)), "mmmm yyyy"),"")))
Remember that this is a single formula, and should be entered all on one line. You can copy the formula down as many rows as necessary in column C, and it should provide the desired information. It only makes a notation in column C if the value in column B is greater than the maximum or less than the minimum of all the foregoing values in column B.
If you have quite a bit of data in your worksheet, you could notice that the formula results in long recalculation times. If this is the case, then you may want to consider using macro that will do the desired analysis and provide the appropriate information. The following macro provides looks backward through the information in column B and provides both a "lowest since" and "highest since" result in columns C and D.
Sub FindHiLow()
Dim orig_cell As Range
Dim orig_val As Integer
Dim orig_row As Integer
Dim rownum As Integer
Dim newcell As Range
Dim new_val As Integer
Dim lowrow As Integer
Dim hirow As Integer
Set orig_cell = ActiveCell
orig_row = ActiveCell.Row
orig_val = orig_cell.Value
' find lowest
lowrow = 0
For rownum = orig_cell.Row - 1 To 1 Step -1
Set newcell = Cells(rownum, 2)
new_val = newcell.Value
If orig_val >= new_val Then
lowrow = rownum
Exit For
End If
Next
If lowrow = 0 Then lowrow = 1
Cells(orig_row, 3).Value = "Lowest since " & Cells(lowrow, 1)
' find highest
hirow = 0
For rownum = orig_cell.Row - 1 To 1 Step -1
Set newcell = Cells(rownum, 2)
new_val = newcell.Value
If orig_val <= new_val Then
hirow = rownum
Exit For
End If
Next
If hirow = 0 Then hirow = 1
Cells(orig_row, 4).Value = "Highest since " & Cells(hirow, 1)
End Sub
Tip #3138 applies to Microsoft Excel versions: 97 2000 2002 2003 2007
More Power! For some people, the prospect of creating macros can be scary. Those who conquer their fears, however, find they become much more confident and productive once they learn how to make Excel do exactly what they want. ExcelTips: The Macros is an invaluable source for learning Excel macros. You are introduced to the topic in bite-sized chunks, pulled from past issues of ExcelTips. Learn at your own pace, exactly the way you want.
Check out ExcelTips: The Macros today!
Want to make Excel do even more? The way is easy when you know how to use macros. This great e-book makes it easy. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Bugs and Pests Tips
ExcelTips
Family Tips
Health Tips
Home Tips
Organizing Tips
WordTips
Advertise on the
ExcelTips Site