Excel guide · 5 min read
How to return the column header of the max value in Excel
=INDEX($B$1:$G$1,MATCH(MAX(B2:G2),B2:G2,0)). MAX finds the highest value in the row, MATCH finds its position, and INDEX returns the header in that position. In Excel 365 or 2021, =XLOOKUP(MAX(B2:G2),B2:G2,$B$1:$G$1) does the same. Copy it down to get the best month for every row.Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Rep | Jan | Feb | Mar | Apr | May | Jun |
| 2 | Ana Ruiz | 18400 | 21250 | 19800 | 24100 | 22900 | 23500 |
| 3 | Ben Okafor | 15200 | 14800 | 17600 | 16900 | 17600 | 15100 |
| 4 | Chloe Martin | 22750 | 20100 | 23300 | 21800 | 19950 | 25400 |
| 5 | Dev Sharma | 12900 | 13450 | 11800 | 15600 | 14200 | 13900 |
| 6 | Farah Ali | 8200 | 11400 | 10750 |
Download this sheet as an Excel practice file (.xlsx)
INDEX and MATCH: works in every version
The sheet holds monthly sales for five reps, January to June. The question is which month was each rep's best. MAX(B2:G2) gives Ana's top figure, 24,100. MATCH(…,B2:G2,0) says it is the 4th cell in the row. INDEX($B$1:$G$1,4) returns the 4th header: Apr.
The dollar signs matter. The header row must stay fixed when you copy the formula down, so it is $B$1:$G$1. The data row must move, so B2:G2 has no dollar signs and becomes B3:G3 on the next row. Without the anchors, the second row looks for its header in row 2 and returns a sales figure instead of a month.
Result: Apr
Apr. Copied down, it returns Mar for Ben, Jun for Chloe and May for Farah.
XLOOKUP version (Excel 365 and 2021)
XLOOKUP takes the value to find, where to look and what to return, so it reads more naturally: look up the max in the row, return from the header row. The same anchoring rules apply.
To show the value with the header, join them: =INDEX($B$1:$G$1,MATCH(MAX(B3:G3),B3:G3,0))&" ("&TEXT(MAX(B3:G3),"#,##0")&")" returns Mar (17,600). The result is text, so keep the plain header formula if other formulas need to use it.
Result: Apr
Apr, the same answer as INDEX and MATCH.
Ties: show every month that hit the max
Ben sold 17,600 in both March and May. INDEX MATCH and XLOOKUP stop at the first match, so they return Mar and never mention May. If you need the last one instead, give XLOOKUP a search mode of -1 (search from the end): =XLOOKUP(MAX(B3:G3),B3:G3,$B$1:$G$1,,0,-1) returns May.
To list all of them, FILTER the header row by the cells equal to the max and join the result with TEXTJOIN. FILTER works across a row as well as down a column. It needs Excel 365 or 2021. On rows without a tie it returns a single month, so you can use it for every row.
Result: Mar, May
Mar, May: both months tied at 17,600.
Lowest month, second best and top 3
Swap MAX for MIN to get each rep's weakest month: Jan for Ana. MIN skips empty cells, so Farah, who joined in April, gets Apr (8,200), not a blank month. A month typed as 0 would count, though, so leave months without data empty or use MINIFS with ">0".
For the second best month, use LARGE(B2:G2,2) in place of MAX: =INDEX($B$1:$G$1,MATCH(LARGE(B2:G2,2),B2:G2,0)) returns Jun. In Excel 365, =TAKE(SORTBY(B1:G1,B2:G2,-1),,3) sorts the headers by Ana's sales and keeps the first three: Apr, Jun, May. If two values tie, LARGE returns the same number twice and MATCH finds the same month both times, so use the SORTBY version when ties are possible.
Result: Apr
Apr: Farah's lowest month, with the three empty months ignored.
The other direction: who had the max in a column
To find which rep won a given month, run the same pattern down the column and return from the name column: =INDEX(A2:A6,MATCH(MAX(E2:E6),E2:E6,0)) returns Ana Ruiz for April. The guide on finding the highest and lowest value covers this case in more detail.
For the single best month in the whole table, find the cell's column with the max of COLUMN where the grid equals its max. The best figure is 25,400. If the max appears twice, this version returns the rightmost column. In Excel 2019 and earlier, confirm it with Ctrl+Shift+Enter. The same idea with ROW returns the rep: =INDEX(A2:A6,MAX((B2:G6=MAX(B2:G6))*ROW(B2:G6))-ROW(A2)+1) gives Chloe Martin.
Result: Jun
Jun: Chloe's 25,400 in June is the best month in the table.
When the wrong month comes back: numbers stored as text
Dev's April figure, 15,600, came in from a CSV as text. MAX ignores text, so it sees 14,200 as the top value and the formula returns May. Nothing looks wrong unless you notice the left-aligned cell or the green triangle. =COUNT(B5:G5) returns 5 for six filled months, which gives it away.
The real fix is converting the cell: select it, click the warning triangle and choose Convert to Number. To make the formula cope in Excel 365, convert inside it with --, as below. Also watch for headers that are real dates: the result then shows as a serial number such as 46113. Format the result cell as mmm, or wrap the formula in TEXT(…,"mmm").
Result: Apr
Apr: with the text converted, Dev's real best month is found.
Highlight each row's max instead
If you only want to see the best month, conditional formatting marks it on every row, ties included.
- Select B2:G6.
- Go to Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format.
- Enter
=B2=MAX($B2:$G2). The $ before the columns keeps every cell comparing with its own row. - Choose a fill colour and click OK.
Common mistakes
Header row not anchored
Write the header range as $B$1:$G$1 and the data row as B2:G2. Copied down without the $ signs, the header range slides to row 2 and returns numbers.
Header range and data row not the same width
If the data is B2:G2, the headers must be B1:G1. Starting the headers at A1 shifts every answer one month to the left without any error.
Only one of several tied months shows
MATCH and XLOOKUP return the first match. Use TEXTJOIN with FILTER to list every tied header.
#N/A on a row with no data yet
MAX of an empty row is 0. Guard it: =IF(COUNT(B6:D6)=0,"No sales",INDEX($B$1:$D$1,MATCH(MAX(B6:D6),B6:D6,0))) returns No sales for Farah's first quarter.
FAQ
How do I find which column has the highest value in Excel?
Use =INDEX(header_row,MATCH(MAX(data_row),data_row,0)) with the header row anchored with $ signs. =MATCH(MAX(B2:G2),B2:G2,0) on its own returns the column position, 4 for Ana.
Can VLOOKUP return the column header?
No. VLOOKUP searches down the first column and returns from columns to its right, so it cannot search across a row and return a header. Use INDEX MATCH or XLOOKUP.
How do I return the header of the lowest value?
Replace MAX with MIN: =INDEX($B$1:$G$1,MATCH(MIN(B2:G2),B2:G2,0)). Empty cells are ignored, but zeros count as values.
Does this work with a max by condition?
Yes. Feed the condition into the value you look for, for example MAXIFS(B2:G2,B1:G1,"<>Jun") for the best month excluding June, then MATCH that value in the row. For Ana it is 24,100, so the header is still Apr.
Functions used
INDEXValue at a positionMATCHPosition of a valueMAXLargest numberMINSmallest numberXLOOKUPModern lookup in any directionFILTERKeeps matching rows, spillsTEXTJOINJoins with a separatorLARGEk-th largestSORTBYSorts by other columns, spillsTAKEFirst or last rows, spillsCOLUMNColumn number of a cellROWRow number of a cellCOUNTCounts numbersTEXTNumber to formatted textMAXIFSLargest value that matches
Related guides
- How to find the highest and lowest value in Excel
- How to do a two-way lookup in Excel
- How to use INDEX MATCH in Excel
- MAX IF in Excel: find the largest value that meets a condition
- Excel formulas cheat sheet: the 25 everyone should know
- How to calculate a weighted score in Excel
- How to transpose rows to columns in Excel
Updated