- Gašper Kamenšek
- November 8, 2016
- 6 Comments

We start with a range of values in Excel (A1:G20).

Now we are looking for a formula to get the closest value to the value we input in cell I1. First we’re looking for the closest value lower than the selected one.

Here’s the formula

=SMALL($A$1:$G$20,COUNTIF($A$1:$G$20,"<"&I1))

The key to this formula is the function SMALL which works like this

=SMALL(Range,n)

And it returns the n-th smallest number in a selected range. In our case, we pair SMALL with COUNTIF which simply gives us a count of how many values are smaller than the chosen number. Once this count is inserted into the SMALL function, we actually get the largest value smaller than the selected number, so exactly what we need.

What about the closest number higher than the selected one?

Here’s the formula

=LARGE($A$1:$G$20,COUNTIF($A$1:$G$20,">"&I1))

The key to this formula is the function LARGE, which is the “big” sister of the SMALL function mentioned above. Here’s the functions syntax.

=LARGE(Range,n)

You would never have guessed it, but LARGE returns the n-th largest number in a selected range. This time the COUNTIF function simply gives us a count of how many values are larger than the chosen number. This in combination with the LARGE function, gives us the smallest value larger than the selected number, so again, just what the doctor ordered.

You can download the sample workbook that I used for all the screenshots here.

This was a very short post that could easily be entitled “what do functions LARGE and SMALL do?”, and trust me, these are two functions that you should know and use during your Excel adventures. Putting aside the obvious use of simply finding the second largest or 10^{th} smallest value, and the use implied in this post, you could actually use them to SUM up the 10 largest values in a range, which I wrote about in THE SUM OF 10 LARGEST VALUES post, which I strongly urge you to read.

Start And End Date Of The Week With Power Query

- October 5, 2018

One of the most popular posts on Excel Unplugged is Formula to ...

Amsterdam Excel Summit and Power BI Summer School in the Netherlands

- June 19, 2018

In Slovenia (where I come from) there is a significant shortage ...

The Amsterdam Excel Summit 2018

- May 10, 2018

Jan Karel Pieterse and Tony de Jonker will give Excel ...

Unlock Excel Conference – Australia

- April 30, 2018

The Unlock Excel Conference took place in April in three cities ...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.

To find out more, including how to control cookies, see here: Cookie Policy

To find out more, including how to control cookies, see here: Cookie Policy

%d bloggers like this:

Hi, considering closest value lower than the selected one, what happens if you select a number in I1 that’s below the minimal number in the range? For example try 2. It returns num error. Is there a way to avoid this? Such for example to express something along the lines: “The smallest number is 12” or something other preferable to an error.

Otherwise great article, thanks for the lessons!

Sure thing, you can do a =IFERROR(SMALL(range,COUNTIF(range,”<"&I1)),"Minimum is "&MIN(range))

Gasper, thank you so much! Your contribution is making learning excel exciting!

Glad I can help…

@Gašper – Do you know a way to implement Small / Large function in Power Query (M)

Yes, you do that in two steps…

First you Sort By the desired column (If small then Ascending If Large then Descending)

=

Table.Sort(#”Changed Type”,{{“Numbers”,Order.Descending}})And then you get the desired element from the desired column by inserting a custom step and give it a column name in Square Brackets and the desired element (0 based) in Curly Brackets

= #”Sorted Rows”[Numbers]{3}

The three means you’re going to get the Fourth largest (since the sort was descending) value