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

How to find a closest value to a chosen number within an Excel range? Let’s do it through a simple example!

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.

Check out our YouTube channel and subscribe for more amazing Excel tricks!

Follow us on LinkedIn.

Check out our brand new R Academy!

Extending the Date Table – Part 1

- November 9, 2021

Let’s look at some crucial tools for creating polished ...

SEQUENCE function – Add it to your toolbelt today

- September 14, 2021

The Excel SEQUENCE function In this article, we’ll ...

Excel FILTER Function – The Function that does Everything

- September 10, 2019

Last year, Microsoft announced the introduction of a new group of ...

XLOOKUP is finally here

- August 28, 2019

Today is most definitely one of the most exciting days of this ...