Written by Allen Wyatt (last updated March 29, 2025)
This tip applies to Excel 2021, 2024, and Excel in Microsoft 365
Isaac notes that many of the functions available in the latest versions of Excel return an array of values, which means that the results "spill" into multiple cells. Often the functions will return too many results for his needs. Isaac wonders, therefore, if there is a way to tell Excel to return, say, only five or six values when multiple values are returned.
There are three relatively easy ways to accomplish this task. Let's say, though, that Isaac is using the SORT function, like the following, to sort the values in the range A2:A150:
=SORT(A2:A150)
You could use just about any other array-producing function desired, but SORT works good to illustrate how you can limit what is returned. The function returns a sorted array of the values in the specified range. That means that it "spills over" to fill 149 cells with the results. Isaac, though, would only like to have the first six results from the array.
The first approach is to wrap the SORT function in the CHOOSEROWS function, in this manner:
=CHOOSEROWS(SORT(A2:A150),1,2,3,4,5,6)
The CHOOSEROWS function returns the specified rows from an array. In this case, the formula specifies that rows 1 through 6 should be returned. If desired, you could throw the SEQUENCE function into the mix:
=CHOOSEROWS(SORT(A2:A150),SEQUENCE(6))
Since the SEQUENCE function returns an array consisting of however many sequential numbers you specify, it is the same as explicitly stating that you want the first six rows returned by the SORT function.
Closely related to CHOOSEROWS is the TAKE function, which can be used to return both rows and columns from an array. If the array contains only a single column—as is the case with the SORT function—then you can simply specify the number of rows desired:
=TAKE(SORT(A2:A150),6)
One advantage to using TAKE is that you can specify whether you want rows or columns from the end of the array. So, for instance, if Isaac wanted the last six rows in the array, then he could use this:
=TAKE(SORT(A2:A150),-6)
The difference here is that the parameter indicating the number of rows is negative.
The third approach is to rely on the INDEX function, which is very similar to using the CHOOSEROWS function:
=INDEX(SORT(A2:A150),SEQUENCE(6))
The difference between INDEX and CHOOSEROWS in this usage is that INDEX requires the use of the SEQUENCE function because it expects an array indicating the rows to return. (In other words, you cannot provide an explicit list of rows as you can with CHOOSEROWS.)
Which of these approaches should you use? It really depends on the version of Excel you are using. All of the functions used in this tip will work with Excel in Microsoft 365. The oldest availability is the INDEX function, which was introduced all the way back in Excel 2003. Both the SORT and SEQUENCE functions are first available in Excel 2021, and both CHOOSEROWS and TAKE in Excel 2024.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10144) applies to Microsoft Excel 2021, 2024, and Excel in Microsoft 365.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
If you need to modify information in a text string, two common functions you can use are SUBSTITUTE and REPLACE. This tip ...
Discover MoreYou may use Excel's trigonometric functions to do some quick calculations, and suddenly notice that the results in your ...
Discover MoreFinding a square root is easy because Excel provides a worksheet function for that purpose. Finding a different root may ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2025-03-30 10:41:39
J. Woolley
The Tip's first approach uses Excel 2024's CHOOSEROWS like this:
=CHOOSEROWS(SORT(A2:A150), 1, 2, 3, 4, 5, 6)
The GetRows function in My Excel Toolbox is similar to CHOOSEROWS; here's the equivalent formula:
=GetRows(SortPlus(A2:A150), 1, 2, 3, 4, 5, 6)
SortPlus is more capable than SORT and does not require Excel 2021; it is described in my comment here: https://excelribbon.tips.net/T012575
The Tip also uses Excel 2024's TAKE like this:
=TAKE(SORT(A2:A150), 6)
My Excel Toolbox's Resize function is similar to TAKE; here's the equivalent formula:
=Resize(SortPlus(A2:A150), 6)
The Tip says, "One advantage to using TAKE is that you can specify whether you want rows or columns from the end of the array." These formulas return the last 6 rows sorted in ascending order (last row last):
=TAKE(SORT(A2:A150), -6)
=Resize(SortPlus(A2:A150), -6)
You can do the same with CHOOSEROWS using these formulas; however, the last 6 rows are reversed (last row first):
=CHOOSEROWS(SORT(A2:A150), -1*SEQUENCE(6))
=CHOOSEROWS(SORT(A2:A150), -1*{1;2;3;4;5;6})
Following up on Alex Blakenburg's comment, the Tip's last formula is
=INDEX(SORT(A2:A150), SEQUENCE(6))
It says, "...INDEX requires the use of the SEQUENCE function because it expects an array indicating the rows to return." These equivalent versions do not require Excel 2021's SEQUENCE:
=INDEX(SORT(A2:A150), {1;2;3;4;5;6})
=INDEX(SortPlus(A2:A150), ForNext(1, 6, , TRUE))
ForNext is described in my comment here: https://excelribbon.tips.net/T012002
Finally, these formulas return the last 6 rows sorted in descending order (last row first):
=INDEX(SortPlus(A2:A150), ForNext(149, 144, -1, TRUE))
=INDEX(SortPlus(A2:A150, , -1), ForNext(1, 6, , TRUE))
That last formula simply changes the sort order from ascending (default) to descending.
See https://sites.google.com/view/MyExcelToolbox/
2025-03-30 01:00:50
Alex Blakenburg
Particularly if you are using Excel 2021 which has Dynamic Array functionality but does not have ByRow or Take, it might be worth noting that this statement the following statement about INDEX is INCORRECT.
"you cannot provide an explicit list of rows as you can with CHOOSEROWS."
The following 2 lines will give the same result:
=CHOOSEROWS(SORT(A2:A150),1,2,3,4,5,6)
=INDEX(SORT(A2:A150),{1;2;3;4;5;6})
To get ALL columns using ChooseRows is a bit easier and the following 2 will give all columns of the range expanded to A:D and sorting column 1 ascending.
=CHOOSEROWS(SORT(A2:D150,1,1))
=INDEX(SORT(A2:D150,1,1),{1;2;3;4;5;6},SEQUENCE(,COLUMNS(A2:D2)))
Selected Column 3 & 1
=CHOOSECOLS(CHOOSEROWS(SORT(A2:D150),1,2,3,4,5,6),3,1)
=INDEX(SORT(A2:D150,1,1),{1;2;3;4;5;6},{3,1})
Note: Row separator is semi-colon ";" column separator is comma ","
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 © 2025 Sharon Parq Associates, Inc.
Comments