How to use the TAKE function
What is the TAKE function?
The TAKE function returns a given number of rows or columns from a 2D cell range or array filtering the remaining rows out.
The TAKE function is available to Excel 365 users and is in the "Array manipulation" category.
Table of Contents
1. Syntax
TAKE(array, rows, [columns])
Back to top
2. Arguments
The TAKE function has three arguments, the first and second argument are required and the third is optional.
array | Required. The source cell range or array. |
rows | Required. The number of contiguous rows to return, a negative number returns contiguous rows from the end. |
[columns] | Optional. The number of contiguous columns to return, a negative number returns contiguous rows from the end. |
3. Example
The picture above shows how the TAKE function returns the two first rows from cell range B2:D5.
Dynamic array formula in cell B9:
The source range is B2:D5 and the second argument is 2. This means that row 1 and row 2 counting from the top is returned to the output array, however, row 3 and 4 are deleted. The TAKE function is useful for resizing arrays, this makes it easier to work with specific rows or columns. For example, you want to know the median number from columns 1 and 2. The TAKE function is very useful for this kind of scenario.
3.1 Explaining formula
You can follow the calculations step by step by pressing the "Evaluate" tool located on the Formula tab on the ribbon. This makes it easier to spot errors and understand the formula in greater detail.
Step 1 - TAKE function
The TAKE function has three arguments, the first two are required. This example needs only the first two arguments.
TAKE(array, rows, [columns])
Step 2 - Populate arguments
The first argument is the array or cell range which is B2:D5. The sond argument is rows and is 2 in this example.
array - B2:D5
rows - 2
[columns] -
Step 3 - Evaluate function
The following lines show how the TAKE function keeps the first two rows and deletes the remaining rows.
TAKE(B2:D5, 2)
becomes
TAKE({89, 27, 26;68, 84, 98;19, 92, 62;37, 63, 45}, 2)
and returns
{89, 27, 26;
68, 84, 98}
4. Example - return columns
The image above demonstrates how to return specific columns using the TAKE function. Cell range B2:D5 contains values, it has four rows and three columns. This example shows how to keep the two first columns and leave the remaining columns out.
Formula in cell B6:
Note that the second argument is not required if you supply a number for the third argument. The function works perfectly as long as you type a number in at least one of argument rows or columns.
5. Example - return rows and columns
The image above demonstrates how to return both rows and columns using the TAKE function. Note that it only returns the intersection of the chosen rows and columns, see the image below.
The intersection are those values that are in both column 1 and 2, and also in rows 1 and 2. The blue rectangles shown in the image above shows both groups, the red rectangle shows the intersection of those two groups.
Formula in cell B9:
TAKE(array, rows, [columns])
This example shows that you can use both the second rows argument and the third columns argument at the same time. Remember that the output is the intersection and not the union.
6. Example - negative values
The TAKE function lets you use negative arguments, this means that the function returns rows/columns from the end. The TAKE function counts columns from left to right and rows from top to bottom.
Formula in cell B9:
However, negative values forces the TAKE function to count the rows from bottom up to the top and the columns from right to the left.
TAKE(array, rows, [columns])
The image above shows that the rows argument is -2 and that takes the two last rows from cell range B2:D5. The columns argument is -2 as well and that takes the two last columns. Only the intersection of these groups are returned to cell B9. The red rectangle in the image above shows the intersection.
7. TAKE function alternative
It is possible to return the two first rows using the OFFSET function, however, the OFFSET function is volatile and may slow down your worksheet if you use many of them. Volatile means that the OFFSET function recalculates more often than regular Excel functions.
Array formula in cell B9:
This array formula should work in most Excel versions. I recommend using the TAKE function in Excel 365, it is not volatile.
7.1 How to enter an array formula
Earlier Excel versions require you to enter array formulas in a specific way in order to show all values in the array. The following steps shows how to enter an array formula in earlier Excel versions. Excel 365 does not have this disadvantage, you can enter all formulas as a regular function in Excel 365.
- Double press with left mouse button on with the left mouse button on cell B9, a prompt appears.
- Type or copy/paste the formula to cell B9.
- Press and hold CTRL + SHIFT simultaneously.
- Press Enter once.
- Release all keys.
The formula now has leading and trailing curly brackets, don't enter these characters yourself. They appear automatically.
7.2 Explaining formula in cell B6
Step 1 - OFFSET function
The OFFSET function returns a reference to a range that is a given number of rows and columns from a given reference.
OFFSET(reference, rows, columns, [height], [width])
Step 2 - Populate arguments
The OFFSET function has five arguments, three are required and two are optional. The rows and columns arguments are not required in this example because we specify the height and width arguments in this example.
reference - B2:D5
rows -
columns -
[height] - 2
[width] - 3
Step 3 - Evaluate OFFSET function
OFFSET(B2:D5,,,2,3)
becomes
OFFSET({89, 27, 26;68, 84, 98;19, 92, 62;37, 63, 45},,,2,3)
and returns
{89, 27, 26; 68, 84, 98}.
8. Example - values in random order
The image above shows a formula that returns values in random order from the two first rows in a given 2D cell range. Cell range B2:D5 contains some random values, it has three columns and four rows.
Dynamic array formula in cell B8:
The formula extracts the two first rows and then returns those values in random order, the returned array has the same size as the two first rows in the source data range.
The formula in cell B8 spills values below and to the right of cell B8 as far as needed. A #SPILL! error is displayed if any of the destination cells are not empty. Delete the nonempty cells and the error goes away.
8.1 Explaining formula in cell B8
Tip! You can follow the formula calculations step by step by using the "Evaluate" tool located on the Formula tab on the ribbon. This makes it easier to spot errors and understand the formula in greater detail.
Step 1 - Extract two first rows
The first argument is B2:D5 and the second argument rows is 2.
TAKE(B2:D5, 2)
becomes
TAKE({89, 27, 26;68, 84, 98;19, 92, 62;37, 63, 45}, 2)
and returns
{89, 27, 26;68, 84, 98}.
This filters the two first rows and leaves the remaining rows out.
Step 2 - Rearrange values to a single row
The TOROW function rearranges values from a 2D cell range or array to a single row.
TOROW(array, [ignore], [scan_by_col])
TOROW(TAKE(B2:D5,2))
becomes
TOROW({89, 27, 26;68, 84, 98})
and returns
{89, 27, 26, 68, 84, 98}.
Step 3 - Count cells
The COLUMNS function returns the number of columns in a given cell range or array.
COLUMNS(array)
COLUMNS(TOROW(TAKE(B2:D5,2)))
becomes
COLUMNS({89, 27, 26, 68, 84, 98})
and returns 6.
Step 4 - Count rows
The ROWS function returns the number of rows in a given cell range or array.
ROWS (array)
ROWS(TAKE(B2:D5,2))
becomes
ROWS({89, 27, 26; 68, 84, 98})
and returns 2.
Step 5 - Create random decimal numbers
The RANDARRAY function returns a table of random numbers across rows and columns.
RANDARRAY([rows], [columns], [min], [max], [whole_number])
RANDARRAY(,COLUMNS(TOROW(TAKE(B2:D5,2))))
becomes
RANDARRAY(,6)
and returns
{0.215398134613085, 0.390607168196479, ... ,0.83231474462401}.
Step 6 - Rearrange values in random order
The SORTBY function allows you to sort values from a cell range or array based on a corresponding cell range or array.
SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2],…)
SORTBY(TOROW(TAKE(B2:D5,2)),RANDARRAY(,COLUMNS(TAKE(B2:D5,2))))
becomes
SORTBY({89, 27, 26, 68, 84, 98}, {0.215398134613085, 0.390607168196479, ... ,0.83231474462401})
and returns
{84, 89, 26, 27, 98, 68}.
Step 7 - Rearrange values to original array size
The WRAPCOLS function rearranges values from a single row to a 2D cell range based on a given number of values per column.
WRAPCOLS(vector, wrap_count, [pad_with])
WRAPCOLS(SORTBY(TOROW(TAKE(B2:D5,2)),RANDARRAY(,COLUMNS(TOROW(TAKE(B2:D5,2))))),ROWS(TAKE(B2:D5,2)))
becomes
WRAPCOLS({84, 89, 26, 27, 98, 68},ROWS(TAKE(B2:D5,2)))
becomes
WRAPCOLS({84, 89, 26, 27, 98, 68}, 2)
and returns
{84, 89, 26; 27, 98, 68}
Step 8 - Shorten formula
The LET function lets you name intermediate calculation results which can shorten formulas considerably and improve performance.
LET(name1, name_value1, calculation_or_name2, [name_value2, calculation_or_name3...])
WRAPCOLS(SORTBY(TOROW(TAKE(B2:D5,2)),RANDARRAY(,COLUMNS(TOROW(TAKE(B2:D5,2))))),TOROW(TAKE(B2:D5,2)))
becomes
LET(z,TAKE(B2:D5,2),x,TOROW(z),WRAPCOLS(SORTBY(x,RANDARRAY(,COLUMNS(x))),ROWS(z)))
9. Example - multiple source ranges
The picture above shows a formula that merges three non-contiguous cell ranges and return values from the two first columns. The three non-contiguous cell ranges are B3:D6, F3:H6, and J3:L6. These cell ranges are merged vertically meaning the first cell range B3:D6 is at the top, the second cell range F3:H6 is joined below B3:D6. The third cell range J3:L6 is merged below F3:H6, together they form a larger array containing three columns and 12 rows.
Dynamic array formula in cell B9:
The TAKE function extracts the first two columns (Item and Quantity) and filters out the third (Price). The output is displayed in cell B9 and cells below and to the right as far as needed. This is a Excel 365 formula and is entered as a regular formula. A #SPILL error is shown if at least one of the destinations cells are not empty.
This technique is useful if data sets are located on different worksheets and you need to perform specific calculations to give columns. For example, the average of each items quantity or the median price etc.
9.1 Explaining formula
Tip! You can follow the formula calculations step by step by using the "Evaluate" tool located on the Formula tab on the ribbon. This makes it easier to spot errors and understand the formula in greater detail.
Step 1 - Stack values horizontally
The VSTACK function lets you combine cell ranges or arrays, it joins data to the first blank cell at the bottom of a cell range or array (vertical stacking)
VSTACK(array1, [array2],...)
VSTACK(B3:D6, F3:H6, J3:L6)
becomes
VSTACK({"Peach", 43, 1.03;"Blueberry", 39, 1.48;"Apple", 46, 1.1;"Grapefruit", 14, 0.72}, {"Mandarin", 29, 0.78;"Raspberry", 33, 1.07;"Plum", 25, 0.9;"Mango", 37, 1.13}, {"Pear", 17, 0.63;"Orange", 31, 1.06;"Lime", 17, 1.27;"Kiwi", 45, 0.58})
and returns
{"Peach", 43, 1.03;
"Blueberry", 39, 1.48;
"Apple", 46, 1.1;
"Grapefruit", 14, 0.72;
"Mandarin", 29, 0.78;
"Raspberry", 33, 1.07;
"Plum", 25, 0.9;
"Mango", 37, 1.13;
"Pear", 17, 0.63;
"Orange", 31, 1.06;
"Lime", 17, 1.27;
"Kiwi", 45, 0.58}
Step 2 - Wrap values to rows
TAKE(VSTACK(B3:D6, F3:H6, J3:L6), , 2)
becomes
TAKE({"Peach", 43, 1.03;
"Blueberry", 39, 1.48;
"Apple", 46, 1.1;
"Grapefruit", 14, 0.72;
"Mandarin", 29, 0.78;
"Raspberry", 33, 1.07;
"Plum", 25, 0.9;
"Mango", 37, 1.13;
"Pear", 17, 0.63;
"Orange", 31, 1.06;
"Lime", 17, 1.27;
"Kiwi", 45, 0.58}, , 2)
and returns
{"Peach", 43;
"Blueberry", 39;
"Apple", 46;
"Grapefruit", 14;
"Mandarin", 29;
"Raspberry", 33;
"Plum", 25;
"Mango", 37;
"Pear", 17;
"Orange", 31;
"Lime", 17;
"Kiwi", 45}
Useful resources
TAKE function - Microsoft support
Excel TAKE function to extract rows or columns from array
'TAKE' function examples
The following article has a formula that contains the TAKE function.
Table of Contents How to use the CHOOSECOLS function How to use the CHOOSEROWS function How to use the DROP […]
Functions in 'Array manipulation' category
The TAKE function function is one of 11 functions in the 'Array manipulation' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form