By Harold Graycar XL Numerics Developer of Excel for Customer Service Professionals
The previous post on this topic included a method for finding the cell address for the maximum or minimum number in a table.
Thanks for the correspondence -- and especially that from Hervé, Saskia and Trevor for the questions about what happens if there are multiple maximum or minimum values.
The previous method sometimes failed where there were multiple maximum or minimum values.
Download Workbook
Enter your email address below to download the sample workbook.
This version shows a different approach that works reliably under that situation too.
- The ‘index table’ method
Instead of setting up the reference row and column against the table as shown in the previous model (shown in light green here):
We use a method that works with an ‘index table’ related to the table we are investigating (shown in blue below). And we set up the ‘index table’ (shown in green below) to have one row for each cell in the blue table.
In the index table:
Row 1, Col 1 refers to cell January, Wk1 in the main table
Row 1, Col 2 refers to cell January, Wk2 in the main table
Row 2, Col 3 refers to cell February, Wk3 in the main table
etc.
It may take a few moments to set up the index table, since it needs to have one row for every cell in the table we are investigating (and could be very long if we have a large number of rows and columns in the table we are investigating).
The aim is to get an entry in the index table for each cell in the original table. In the index table column headed ‘Match’, we do a computation on whether the cell in the original table matches the Maximum (or Minimum if selected).
The formula for each cell in the Match column is:
=IF(INDEX(MyTable,[@Row],[@Col]+1)=Selected,TRUE,"")
This may look a bit complex, but it’s not too difficult if dissected, and it says in English:
Go to the blue table (MyTable). Using the INDEX function, go to the cell given by the Row and Column numbers in the green table.
But wait a minute . . . . how does the ‘+1’ come into the formula?
The first column of MyTable contains the month names, and since we are only interested in the numbers, we add one to the column so we can skip over the month names. So that means we are considering the Wk1 column to be the first column, the Wk2 column to be the second column, whereas in the Excel table structure, the Month is considered to be the first column and Wk1 is the second column etc.
For each cell in the original table, the index table entry is TRUE if the cell matches the Maximum (or Minimum if selected) and blank if there is no match.
This leaves us with a TRUE value in the index table for every match. It’s easy to see and verify, too.
- Getting the match information from the index table
Say this is our result after refreshing the worksheet:
To find the number of matches, we count the number of times the value TRUE appears in the index table column ‘Match’:
=COUNTIF(IndexTable[Match],TRUE)
To find the table position of the first match, the row of the first match in the original table is given by the OFFSET function:
=OFFSET(IndexTable[[#Headers],[Row]],MATCH(TRUE,IndexTable[Match],0),0)
i.e. find the first value of TRUE down the index table (the MATCH function will provide the number of entries down the index table where the first match is located), then use the OFFSET function to count down that same number of rows from the top of the Row column in the index table.
Similarly to finding the row of the first match, the column of the first match in the original table is given by the OFFSET function:
=OFFSET(IndexTable[[#Headers],[Col]],MATCH(TRUE,IndexTable[Match],0),0)
i.e. find the first value of TRUE down the index table, then use the OFFSET function to count down that same number of rows from the top of the Col column in the index table.
Once the row and column of the first match are found, OFFSET can be used again to locate the first matched call in the original table, and to work out its cell address:
=CELL("address",OFFSET(MyTable[[#Headers],[Month]],$L$12,$L$13))
- Some neat conditional formatting
Mynda recently discussed using logical functions to drive conditional formatting, so in this example, I’ve extended that to differentiate between maximum values being found or minimum values being found.
The cell used to denote Maximum or Minimum has the range name ‘SelectType’
So we can set conditional formatting in the original table to be driven by two logical conditions:
If SelectType is set to Minimum, then paint the minimum cells red:
If SelectType is set to Maximum, then paint the maximum cells green:
So, we’ve covered a more reliable way to locate the row number, column number and cell address largest and smallest numbers – plus some more effective conditional formatting for easily highlighting the locations of those numbers.
There’s a whole lot more on how to use these conditional formatting and formula techniques in the Excel for Customer Service Professionals course.
Harold
Hi Roger,
Thanks for the feedback.
Yes, conditional formatting works a treat, and the use of conditional formatting is explained in the first article and demonstrated in the second sheet of the workbook.
The challenge we set out to meet is how to get the cell address of one or more matching cells — as far as I know, something that’s not available with conditional formatting.
Cheers,
Harold
Roger Govier
But Harold, the point is that a simple copy of the table as I described, will allow you to determine where the values occur.
I placed my copy table stating at U4, and called it Table2
Then, the CF in Table 1 merely needs to be =U5=1
Then, each of the cells in your Table1 will get highlighted Green to correspond with the pattern of 1’s in Table2
Roger Govier
Harold
Let me apologise sincerely.
Had I read the article thoroughly first time, instead of just skimming it, I would have realised it was little to do with Conditional Formatting, but about reading the cell address where the high value resided.
Your method does that excellently, whereas my suggestion would not have given any such result.
Please accept my apology.
Harold
Hi Roger,
Thank you for the reply – perhaps the original article was a bit long . . . .
In any case, as you noted, conditional formatting works well (and you don’t even need to do the table of 1’s and 0’s).
However, you need to know the cell address if you want to do any further computation that relies on the address of the maximum or minimum.
If you know the address and the row/column position in the table (computed in the sample workbook), you can use the OFFSET function to answer questions such as:
In what month does the maximum value occur?
In what week does the maximum value occur?
etc.
Cheers,
Harold
Roger Govier
Hi Mynda
This does seem to be a bit of an overkill to achieve the result.
Why wouldn’t you just copy the whole table, and paste it somewhere to the right of the source table then simply enter the formula
=–(MyTable[@Wk1]=Selected) in Wk1 January of the new table and copy across and down.
You would then have a matrix of 1’s and 0’s, with the 1’s representing where the max values occurred in your source table.
If you wanted, a simple CF of Cell Value =1 formatted Green would show the data neatly.
Far easier than constructing an index table and going through all those steps.