where data (B5:F15) and header (B4:F4) are named ranges. In a standard configuration, the INDEX function retrieves a value at a given row and column. For example, to get the value at row 2 and column 3 in a given range: However, INDEX has a special trick – the ability to retrieve entire columns and rows. The syntax involves supplying zero for the “other” argument. If you want an entire column, you supply row as zero. If you want an entire row, you supply column as zero: In the example shown, we want to find the maximum value in a given column. The twist is that the column needs to be variable so it can be easily changed. In F5, the formula is: Working from the inside out, we first use the MATCH function to get the “index” of the column requested in cell J4: With “Green” in J4, the MATCH function returns 3, since Green is the third value in the named range header. After MATCH returns a result, the formula can be simplified to this: With zero provided as the row_number, INDEX returns all values in column 3 of the named range data. The result is returned to the MAX function in an array like this: And MAX returns the final result, 93.
Minimum value
To get the minimum value with a variable column, you can simply replace the MAX function with the MIN function. The formula in J6 is:
With FILTER
The new FILTER function can also be used to solve this problem, since FILTER can filter data by row or by column. The trick is to construct a logical filter that will exclude other columns. COUNTIF works well in this case, but it must be configured “backwards”, with J4 as the range, and header for criteria: After COUNTIF runs, we have: And FILTER delivers the 3rd column to MAX, same as the INDEX function above. As an alternative to COUNTIF, you can use ISNUMBER + MATCH instead: The MATCH function is again set up “backwards”, so that we get an array with 5 values that will serve as the logical filter. After ISNUMBER and MATCH run, we have: And FILTER again delivers the 3rd column to MAX.
Dave Bruns
Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.