Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Finding the Lowest Numbers.
Written by Allen Wyatt (last updated May 3, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
You may have a need at some point to find the lowest numbers in a list of values. This is relatively easy to do if you use the SMALL worksheet function. The function takes two parameters: the range of the values to be evaluated and an indicator of which smallest number you want. For instance, the following will return the second lowest number in the range of A1:A100:
=SMALL(A1:A100,2)
If you wanted to know the two lowest numbers in the range, then use two formulas containing the SMALL function—one with 1 as the second parameter (for the lowest number) and one with 2 as the second parameter (for the second lowest number).
There are situations, of course, where the two smallest numbers in the range could actually be the same number. For instance, if the lowest number is 3 and there is a second 3 in the list, then both the lowest numbers will be the same. If you want the two lowest unique numbers then you will need to use a macro to determine them.
Function SMALLn(rng As Range, n) Application.Volatile SMALLn = False If n < 1 Then Exit Function Dim i As Long, j As Long, k As Long, min, arr, arr2 arr = Application.Transpose(rng) ReDim arr2(n - 1) min = Application.WorksheetFunction.Min(arr) j = UBound(arr) k = 0 arr2(k) = min For i = 1 To j If Application.Small(arr, i) <> arr2(k) Then k = k + 1 arr2(k) = Application.Small(arr, i) If k = n - 1 Then SMALLn = arr2(k) Exit For End If End If Next i End Function
This user-defined function is used in the following manner:
=SMALLn(A1:A100,2)
When called like this, the function returns the second lowest unique value in the specified range.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10944) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Finding the Lowest Numbers.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
The INT function allows you to convert a value to an integer. The effect the function has depends on the characteristics ...
Discover MoreFunctions are at the heart of Excel's power in working with data. One of the most misunderstood functions provided by ...
Discover MoreThe PROPER worksheet function is used to change the case of text so that the first letter of each word is capitalized. If ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-05-03 10:15:37
Don Small
No need for a macro. There's a much simpler way to determine the smallest unique number: =SMALL(UNIQUE(A1:A12),2)
2023-05-03 05:56:17
Kiwerry
Thank you, Micky, for your UDF.
I always have Option Explicit in my modules, so had to add some Dimension statements but then it worked fine.
2016-09-07 08:48:51
Ron Owens
I need a formula to select the low four numbers from a column and then add those four numbers.
These are golf match scores. I need to select the low four for a team then add those four scores for a team total.
2014-12-14 15:38:24
Michael (Micky) Avidan
@Locke,
1) No problem (as for your addition to my formula).
2) in the UDF - you may omit the: nn = Rng.Count
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL
2014-12-14 14:12:39
@Micky
No problem. In the cases where you can make the assumption that your range is all numbers (which would be most cases) I would use your solution in a heart beat. I just wanted to add to your solution so that it behaved a little more like the SMALL/LARGE functions. You're formula solution is perfectly valid. :)
Nice UDF!
2014-12-14 06:59:04
Michael (Micky) Avidan
@Locke,
My suggested formula was written as per the above tip - therefor I didn't considered textual values within the range.
Here is my suggestion for a "sufisticated" UDF.
a) Rng is for the Range of cells.
b) The second argument is the position k.
c) The last argument should be "S" for Small or "L" for Large.
----------------------------------------------
Function Large_SmallUnique(Rng As Range, k, LS)
Dim NewList As New Collection
nn = Rng.Count
On Error Resume Next
For Each CL In Rng
NewList.Add CL, CStr(CL)
Next
ReDim arr(NewList.Count)
For P = 1 To NewList.Count
arr(P) = NewList(P)
Next
If UCase(LS) = "L" Then
Large_SmallUnique = Application.Large(arr, k)
Else
Large_SmallUnique = Application.Small(arr, k)
End If
End Function
-------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL
2014-12-13 19:18:03
Michael (Micky) Avidan
@Roy,
Allens coding is a USER DEFINED FUNCTION - and as such it MUST be typed into a Module and not in both places you have mentioned.
My previous disclosure remains the same.
Try to study the following link:
http://dmcritchie.mvps.org/excel/getstarted.htm
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL
2014-12-13 15:46:46
@Roy
You'll need to create a module. UDFs don't work in Sheet or Workbook objects.
2014-12-13 15:41:58
@Micky
In playing with your formula I discovered for the first time that SMALL/LARGE ignore TRUE/FALSE values. Always a new discovery! Not sure how I never realized it before.
I noticed that the formula breaks if your range contains text or boolean values. This can be overcome with the following modification:
=SMALL(IF(FREQUENCY(MATCH($A$1:$A$10,$A$1:$A$10,0),MATCH($A$1:$A$10,$A$1:$A$10,0)),A$1:A$11),ROW(A1))
2014-12-13 10:00:54
Ralph Shumaker
In a large worksheet, I decide to find the smallest number, so I entered =, then END, then Home. to find all active cells. I then edited the formula to =small(A1:K7580) and received an error. then I added ,2) to the formula and got a 0. So I increased the decimals and still received a zero. So I thought the lowest number must be zero or the formula will not work if some cells contain text, so I edited the formula to =large(A1:a100,1) and received a large number. I then edited my small formula and received a -121 and the other formulas re-computed. Now I'm wondering why my initial entry did not work.
2014-12-13 06:52:59
Roy
@Micky
My ignorance is showing, I copied Allens coding into both sheet1 and thisworkbook but the function was not available. What did I do wrong?
Roy
2014-12-13 06:13:48
Michael (Micky) Avidan
@Roy,
Correct assumption, especially as far as my formula is concerned.
***Disclosure:
I didn't examine the proposed UDF.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL
2014-12-13 06:07:52
Michael (Micky) Avidan
No need for a UDF.
Assume the range of numbers are in A1:A10:
3
-3
6
7
-2
8
5
5
-2
-3
Now, type the following formula into cell D1 and copy down as far as needed.
=SMALL(IF(FREQUENCY(A$1:A$10,A$1:A$10),A$1:A$11),ROW(A1))
Double click to see a pictured demonstration:
http://postimg.org/image/phqgmhff3/
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL
2014-12-13 06:00:51
Roy
One assumes you could also use the principle for obtaining the LARGEst unique numbers.
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments