Sub topic 5
Finding the smallest and largest values with MIN and MAX
MIN returns the smallest number in the values you give it. MAX returns the largest. This chapter assumes you can enter values in cells, select ranges, and start a formula with an equals sign. It also assumes you know the basic shape of a function call from the earlier chapter on function syntax.
By the end you will be able to use both functions on ranges and on several arguments, explain how they treat blanks, text, and logical values, and avoid the common surprises, such as a MIN that returns 0 when you expected a real minimum.
The basic formulas
Both functions take one or more arguments. Each argument can be a cell, a range, a typed number, or another formula.
=MIN(B2:B6)
=MAX(B2:B6)Suppose B2:B6 holds monthly sales of 120, 95, 210, 180, and 150. Then =MIN(B2:B6) returns 95 and =MAX(B2:B6) returns 210.
The spread between the two is called the range of the data. It shows how widely the values vary. You get it by subtracting one result from the other.
=MIN(B2:B6)
=MAX(B2:B6)
=MAX(B2:B6)-MIN(B2:B6)With the sample values above, the third formula returns 210 - 95 = 115.
Note that "range" has two meanings in this tutorial. A cell range such as B2:B6 is a block of cells. The statistical range is the difference between the largest and smallest value. The context makes clear which one is meant.
What MIN and MAX read
Like SUM and AVERAGE, MIN and MAX work on numbers. When you pass a range or a cell reference, they apply these rules.
| Content of a referenced cell | Effect on MIN and MAX |
|---|---|
| A number (including negative numbers and dates) | Used |
| An empty cell | Ignored |
| Text, including numbers stored as text such as "42" | Ignored |
| TRUE or FALSE | Ignored |
| An error value such as #N/A | The formula returns that error |
The first row deserves attention. Excel stores dates and times as numbers, so MIN over a column of dates returns the earliest date and MAX returns the latest. The result appears as a plain serial number unless the cell has a date format. If you see something like 45992 where you expected a date, change the cell's number format to a date format.
=MIN(A2:A20)
=MAX(A2:A20)Typed arguments behave differently
The ignore rules above apply to values that come from cells and ranges. Values you type directly into the formula are treated more strictly.
- A logical value typed in, such as
=MAX(TRUE, 5), is counted as a number. TRUE counts as 1 and FALSE counts as 0. - Text that looks like a number, typed in quotes, such as
=MAX("7", 3), is converted to a number, so the result is 7. - Text that cannot be converted, such as
=MAX("abc", 3), returns #VALUE!.
You rarely type such arguments on purpose. The difference matters when a formula builds its arguments, for example with a comparison like A2>5. If that comparison is passed directly as an argument, it is a typed logical value and counts as 0 or 1. If the same TRUE and FALSE values sit in cells and you pass the range, they are ignored.
The empty-range result
If none of the arguments contain a number, MIN and MAX both return 0. They do not return an error.
=MIN(C2:C6)If C2:C6 is empty or holds only text, this formula shows 0. A zero looks like a real answer, so this is easy to miss. It is a different failure from AVERAGE, which returns #DIV/0! on the same input.
The safe pattern is the same one used for AVERAGE: test with COUNT first.
=IF(COUNT(C2:C6)=0, "No data", MIN(C2:C6))COUNT tallies the numeric cells. When it returns 0, the formula shows a label instead of a misleading zero.
Blanks versus zeros
A blank cell is ignored. A cell that contains the number 0 is not. This distinction changes MIN results.
Imagine B2:B6 holds 40, 25, a blank, 60, and 30. =MIN(B2:B6) returns 25, because the blank is skipped. If someone types 0 into the empty cell, the same formula now returns 0.
This often happens when data is imported or when a formula fills a column. Consider a formula in B4 such as =IF(A4="", 0, A4). It puts a real 0 into the cell, and MIN will now report 0 for the whole column. If missing values should not count, return an empty string with "" instead. An empty string is text, so MIN ignores it.
=IF(A4="", "", A4)Formatting can also hide a zero. A custom number format or the setting that hides zero values makes a 0 look blank, even though MIN still sees it. When a minimum looks wrong, select the cell and read the formula bar to see its actual content.
Several arguments and mixed inputs
Like SUM, MIN and MAX accept many arguments, and you can mix ranges, single cells, and constants.
=MAX(B2:B6, D2:D6, 100)This returns the largest value found in both ranges and the constant 100. A common use is to set a floor or a ceiling.
=MAX(B2, 0)
=MIN(B2, 1000)The first formula returns B2, but never less than 0. The second returns B2, but never more than 1000. This is a compact way to keep a calculated value inside limits without an IF.
Both of these also work for comparing two cells. =MAX(B2, C2) returns whichever of the two is larger.
Whole-column references
You can pass an entire column, such as =MAX(B:B). This keeps working as you add rows. It has two cautions.
- Any stray number in the column counts, including a total at the bottom or a number in a header row. A total in B100 would become the maximum.
- Do not put the formula inside the column it reads.
=MAX(B:B)typed in B10 creates a circular reference, and Excel warns you.
Put the formula in a different column, or use a bounded range such as B2:B500 when the area is known.
Finding which row holds the extreme value
MIN and MAX return a value, not a position. To find who or what produced the value, combine them with a lookup. A common approach uses INDEX and MATCH.
=INDEX(A2:A6, MATCH(MAX(B2:B6), B2:B6, 0))Here, MAX finds the largest number in B2:B6. MATCH finds its position within that range, and the final argument 0 asks for an exact match. INDEX then returns the entry at that position from A2:A6, for example the name of the salesperson. If two rows tie for the maximum, the formula returns the first one.
Errors
If any cell in the range holds an error, MIN and MAX return that error. One #N/A in B4 makes =MAX(B2:B6) return #N/A. Fix the source cell, or guard the formula. The AGGREGATE function can skip errors, as in =AGGREGATE(14, 6, B2:B6, 1), which returns the largest value while ignoring errors. Here 14 selects the LARGE function, 6 means ignore errors, and the final 1 asks for the first largest value. Use =AGGREGATE(15, 6, B2:B6, 1) for the smallest.
Common mistakes
- Numbers stored as text. Imported data often has numbers left-aligned with a small green triangle in the corner. MIN and MAX ignore them, so the result comes from a smaller set of values than you think. Compare
=COUNT(B2:B6)with=COUNTA(B2:B6). If COUNTA is larger, some cells are not numeric. - Hidden zeros or placeholder values. Values like 0 or -999 used as "missing" markers become the minimum.
- Hidden or filtered rows. MIN and MAX still read them. Use SUBTOTAL with function number 105 for MIN or 104 for MAX when you want filtered rows excluded. That is covered in a later chapter.
- A total inside the range. If the range includes a total row, the total is usually the maximum.
A worked check
Put these values in B2:B7: 52, 47, blank, "n/a" (text), 61, TRUE. Predict the results before you try them.
=MIN(B2:B7)
=MAX(B2:B7)
=COUNT(B2:B7)The blank, the text, and the TRUE in a cell are all ignored. MIN returns 47, MAX returns 61, and COUNT returns 3.
Exercise
B2:B6 contains 18, a blank cell, the text "20" (stored as text), 7, and 31. What do =MIN(B2:B6) and =MAX(B2:B6) return, and what would change if the blank cell held the number 0?
Show answer
MIN returns 7 and MAX returns 31. The blank is ignored and the text "20" in a cell is ignored, so only 18, 7, and 31 are compared. If the blank cell held 0, MIN would return 0 and MAX would still return 31.
Exercise
Write a formula that returns the smallest value in C2:C10 but shows "No data" when the range has no numbers. Explain why the guard is needed.
Show answer
=IF(COUNT(C2:C10)=0, "No data", MIN(C2:C10)). The guard is needed because MIN returns 0 when the range has no numbers, and a 0 looks like a real result.