=MAKEARRAY(rows, columns, lambda)
- rows - The number of rows to create as a whole number.
- columns - The number of columns to create as a whole number.
- lambda - A LAMBDA with two parameters, the row number and column number of each cell, or the name of a function.
Using the MAKEARRAY function
The MAKEARRAY function creates an array with a given number of rows and columns, and runs a LAMBDA formula to calculate each value. If you ask MAKEARRAY for 5 rows and 7 columns, it runs the LAMBDA 35 times and returns a 5 x 7 array that spills onto the worksheet. For a general introduction to arrays, see Arrays in Excel.
The easiest way to think about MAKEARRAY is this: it's the one-formula version of a formula you copy across and down. A formula like that usually depends on mixed references like $B5 and C$4, which change as the formula is copied. With MAKEARRAY, the LAMBDA is the formula for one cell, and the variables r and c take the place of the mixed references.
Unlike MAP, BYROW, and the other LAMBDA helper functions, MAKEARRAY doesn't start with data; it starts with the size of the final array. The variables r and c are just numbers that represent the row and column number of the "current" cell as MAKEARRAY traverses the array. To fetch data from the worksheet, many MAKEARRAY formulas use the INDEX function.
Because Excel formulas can often spill a grid without any help, one of the trickiest aspects of MAKEARRAY is knowing when to use it. See When to use MAKEARRAY for a summary.
Key features
- A one-formula replacement for a formula you would otherwise copy across and down.
- Builds an array from a given size, not from data. The LAMBDA supplies each value.
- Runs the LAMBDA once per cell, passing in the current row and column number.
randcare positions, not values. To get a value from the worksheet, use INDEX:INDEX(range,r).- The LAMBDA must return a single value for each cell. A LAMBDA that returns an array will result in #CALC!.
- Accepts a function name, like MAX, or a named LAMBDA, in place of a LAMBDA.
- Isn't needed when a formula already spills across rows and columns.
Table of contents
- Basic examples
- Multiplication table
- Price table with INDEX
- When to use MAKEARRAY
- Days per month for each project
- Running total with expanding ranges
- Sort values in each row
- List names by group
- Names in a two-way table
- Correlation matrix
- Notes
Basic examples
MAKEARRAY takes three arguments: rows, columns, and a LAMBDA with two parameters. The first parameter receives the row number of the current cell, and the second receives the column number. You can name them anything you like, but r and c are typical. These two formulas show what r and c contain in an array with 2 rows and 3 columns:
=MAKEARRAY(2,3,LAMBDA(r,c,r)) // row numbers, returns {1,1,1;2,2,2}
=MAKEARRAY(2,3,LAMBDA(r,c,c)) // column numbers, returns {1,2,3;1,2,3}
Note that MAKEARRAY traverses across columns, moves down a row, and repeats. You can use r and c in a calculation as needed. If you ignore them, every cell gets the same value:
=MAKEARRAY(2,3,LAMBDA(r,c,r*c)) // returns {1,2,3;2,4,6}
=MAKEARRAY(2,3,LAMBDA(r,c,"x")) // returns {"x","x","x";"x","x","x"}
=MAKEARRAY(2,3,LAMBDA(r,c,CHAR(64+r)&c)) // returns {"A1","A2","A3";"B1","B2","B3"}
The LAMBDA always takes both parameters, even when the result has just one column:
=MAKEARRAY(3,1,LAMBDA(r,c,r^2)) // returns {1;4;9}
Instead of a LAMBDA, you can give MAKEARRAY the name of a function, which receives the row number and column number as its two arguments:
=MAKEARRAY(3,3,MAX) // returns {1,2,3;2,2,3;3,3,3}
Multiplication table
A multiplication table is the clearest way to see how MAKEARRAY works, because you can see r and c in the result. In the worksheet below, the number of rows is in cell C5 and the number of columns is in cell C6. The formula in E5 is:
=MAKEARRAY(C5,C6,LAMBDA(r,c,r*c))

MAKEARRAY creates an array with 5 rows and 7 columns, then runs the LAMBDA once for each of the 35 cells. Note that r and c are positions in the result, not worksheet rows and columns. The first value (1) lands in cell E5, when r and c are both 1. In the third row and fourth column of the result, r is 3, c is 4, and r*c returns 12, as you can see in cell H7. If you change the numbers in C5 or C6, the table resizes automatically.
MAKEARRAY is not the only way to build this table. The SEQUENCE function can do it too, because math with a vertical array and a horizontal array returns a grid:
=SEQUENCE(C5)*SEQUENCE(,C6)
You can also use a more traditional approach based on mixed references. See Multiplication table formula for details.
Price table with INDEX
Since r and c are just numbers, how do you use values from the worksheet? The answer is the INDEX function. In the worksheet below, the goal is to calculate each price in column B at each discount in row 4. The traditional solution is a formula like this, entered in C5 and copied across and down:
=$B5*(1-C$4)
Here, $B5 locks the column so the formula always gets a price from column B, and C$4 locks the row so the formula always gets a discount from row 4. To do the same thing in a single formula, replace each mixed reference with INDEX: $B5 becomes INDEX(B5:B9,r), and C$4 becomes INDEX(C4:F4,c). The formula in C5 is:
=MAKEARRAY(ROWS(B5:B9),COLUMNS(C4:F4),LAMBDA(r,c,INDEX(B5:B9,r)*(1-INDEX(C4:F4,c))))

The ROWS and COLUMNS functions get the size from the data: 5 rows, one for each price, and 4 columns, one for each discount. Inside the LAMBDA, INDEX(B5:B9,r) returns the price for the current row and INDEX(C4:F4,c) returns the discount for the current column. For cell E6, in the second row and third column of the result, r is 2 and c is 3, so the calculation looks like this:
=25*(1-0.15) // returns 21.25
You can make the formula above a little easier to read by using the LET function to name variables like this:
=MAKEARRAY(ROWS(B5:B9),COLUMNS(C4:F4),LAMBDA(r,c,
LET(
price,INDEX(B5:B9,r),
discount,INDEX(C4:F4,c),
price*(1-discount)
)
))
The last line, price*(1-discount), now reads like the original formula, =$B5*(1-C$4).
This swap from mixed references to INDEX is the pattern behind most formulas on this page. However, you don't really need MAKEARRAY for this example either, because this formula returns the same result in Excel 2021+ due to dynamic arrays:
=B5:B9*(1-C4:F4)
So when do you need MAKEARRAY?
When to use MAKEARRAY
As the examples above show, Excel will often spill into a grid without any help. When one range is vertical and the other is horizontal, a formula like =B5:B9*(1-C4:F4) returns a result for every combination, and you don't need MAKEARRAY. MAKEARRAY is useful when a formula you would write for one cell won't spill across rows and columns when you give it ranges. There are two common reasons why that might happen:
- The formula uses a function that returns one result for a whole range, like MIN, MAX, SUM, or CORREL. See Days per month for each project, Running total with expanding ranges, and Correlation matrix.
- The formula needs a list for each row or column, like the sorted values in a row or the names in a group. Excel formulas won't return a separate array for each row (an array of arrays), so MAP and BYROW return #CALC!. MAKEARRAY works around this limit because it asks for one value at a time. See Sort values in each row, List names by group, and Names in a two-way table.
Note that two other common patterns don't need MAKEARRAY. (1) SUMIFS, COUNTIFS, and AVERAGEIFS will spill a two-way summary when you give them a vertical array for one set of criteria and a horizontal array for the other, as explained in Dynamic two-way sum. (2) A two-way lookup will spill when INDEX gets its row and column numbers from XMATCH:
=INDEX(data,XMATCH(row_values,row_labels),XMATCH(col_values,col_labels))
However, nesting one XLOOKUP inside another won't spill this way. It returns #VALUE! when both lookup values are arrays. For more on two-way lookups, see Two-way lookup with INDEX and MATCH.
Days per month for each project
Here is a problem where MAKEARRAY is useful. In the worksheet below, each project has a start date and an end date, and the goal is to count the days each project runs in each month. The first day of each month is in F4:K4, formatted to show the month name. For one project and one month, the formula is:
=MAX(0,MIN($D5,EOMONTH(F$4,0))-MAX($C5,F$4)+1)
This formula works fine when copied across and down. However, if we try to calculate the whole grid at once by using ranges instead, the formula returns #VALUE!:
=MAX(0,MIN(D5:D9,EOMONTH(F4:K4,0))-MAX(C5:C9,F4:K4)+1) // returns #VALUE!
There are two problems. First, EOMONTH returns #VALUE! when you give it a range, as explained in Why some Excel functions won't spill. Second, even if you fix that with a plus sign (EOMONTH(+F4:K4,0)), MIN and MAX each return one result for all the dates combined, so the formula returns a single 0 instead of a grid. To solve the problem, the formula in F5 uses the same INDEX pattern as the previous example, with LET to give each value a name:
=MAKEARRAY(ROWS(C5:C9),COLUMNS(F4:K4),LAMBDA(r,c,
LET(
start,INDEX(C5:C9,r),
end,INDEX(D5:D9,r),
month,INDEX(F4:K4,c),
MAX(0,MIN(end,EOMONTH(month,0))-MAX(start,month)+1)
)
))

For each cell, start and end are the dates for the current project, and month is the first day of the current month. The EOMONTH function returns the last day of that month. The overlap runs from the later of the two start dates to the earlier of the two end dates, and adding 1 counts both the first and last day. When a project doesn't overlap a month, the result is negative, and MAX returns 0 instead.
Because MIN and MAX only see one project and one month at a time, they work correctly. For example, Charlie runs from March 15 to May 10, which is 17 days in March (cell H7), 30 days in April, and 10 days in May. The same pattern works for other calculations that need a cap or a limit for each cell in a grid. For more on the date logic, see Calculate date overlap in days.
Running total with expanding ranges
Because r and c are numbers, you can also use them to build a range. In the worksheet below, the goal is to calculate a running total of sales for each product across the months. The traditional solution is to use an expanding reference like =SUM($C5:C5), copied across and down, where the range grows as the formula is copied across columns. The formula in J5 does the same thing in one formula:
=MAKEARRAY(ROWS(C5:H9),COLUMNS(C5:H9),LAMBDA(r,c,SUM(INDEX(C5:H9,r,1):INDEX(C5:H9,r,c))))

INDEX returns a cell reference, so you can join two INDEX functions with the range operator (:) to create a range. INDEX(C5:H9,r,1) is the first cell in the current row, and INDEX(C5:H9,r,c) is the cell in the current column. For cell M6, in the second row and fourth column of the result, this creates the range C6:F6, and SUM returns 20. With each new column the range is one cell wider, just like the copied formula.
Why not use the SCAN function? SCAN is the usual way to create a running total, but it runs through the entire range without stopping, so the total doesn't start over on each row. And you can't run SCAN once per row with BYROW, because each row returns an array of totals:
=BYROW(C5:H9,LAMBDA(x,SCAN(0,x,LAMBDA(a,v,a+v)))) // returns #CALC!
However, you can make SCAN work by starting the total over in the first column. This formula returns the same result:
=SCAN(0,C5:H9,LAMBDA(a,v,IF(COLUMN(v)=COLUMN(C5),v,a+v)))
For more on running totals, see Calculate running total.
Sort values in each row
Sorting the values within each row is surprisingly hard in Excel, because the SORT function is designed to keep rows and columns together. In the worksheet below, the goal is to sort each person's test scores from high to low. You might try SORT with by_col set to TRUE, but this doesn't work:
=SORT(C5:G10,,-1,TRUE) // sorts only the first row
This formula sorts the columns by the scores in the first row, so only Ann's scores end up in order. The scores in the other rows are rearranged to stay with Ann's. On a single row, =SORT(C5:G5,,-1,TRUE) works fine, but you can't run it once per row with BYROW, because each row returns an array of scores:
=BYROW(C5:G10,LAMBDA(x,SORT(x,,-1,TRUE))) // returns #CALC!
The solution is to ask for one value at a time with MAKEARRAY and LARGE. The formula in I5 is:
=MAKEARRAY(ROWS(C5:G10),COLUMNS(C5:G10),LAMBDA(r,c,LARGE(INDEX(C5:G10,r,0),c)))

When the column number is zero, INDEX returns an entire row, so INDEX(C5:G10,r,0) gets all the scores for the current person. For Ben, in the second row, the result is {55,60,99,70,62}. The LARGE function returns the nth largest value in a set of numbers, and c supplies n. In the first column of the result, LARGE returns the largest score, in the second column it returns the second largest, and so on. Notice that c does two jobs here: as a position in the result and as an argument for LARGE. The final result for Ben is {99,70,62,60,55}.
To sort from low to high, replace LARGE with the SMALL function. To return only the top 3 scores for each person, set columns to 3:
=MAKEARRAY(ROWS(C5:G10),3,LAMBDA(r,c,LARGE(INDEX(C5:G10,r,0),c)))
LARGE and SMALL only work with numbers. To sort text values in each row, use SORT for one row, and pick one value with INDEX:
=MAKEARRAY(ROWS(data),COLUMNS(data),LAMBDA(r,c,INDEX(SORT(INDEX(data,r,0),,1,TRUE),c)))
For more on LARGE, see Nth largest value.
List names by group
A common problem in Excel is to list the items in each group. In the worksheet below, the goal is to list the names on each team in a single row. The formula for one team is easy: =FILTER(B5:B16,C5:C16=E5) returns all the names on the team in E5, and you can copy a formula like this down for each team. However, if we try to give FILTER all the teams at once with the spill reference E5#, the formula returns #N/A:
=FILTER(B5:B16,C5:C16=E5#) // returns #N/A
This happens because Excel pairs the two ranges item by item instead of checking every team: C5 is compared to the first team in E5#, C6 to the second team, and so on. With 12 rows of data and just 3 teams, the expression returns #N/A for the last 9 rows. Can we use MAP to run FILTER once for each team? No, because each team returns a list of names, which would create an array of arrays:
=MAP(E5#,LAMBDA(t,FILTER(B5:B16,C5:C16=t))) // returns #CALC!
MAKEARRAY solves this problem by running FILTER in each cell and keeping just one name. The formula in F5 is:
=MAKEARRAY(ROWS(E5#),MAX(COUNTIF(C5:C16,C5:C16)),LAMBDA(r,c,IFERROR(INDEX(FILTER(B5:B16,C5:C16=INDEX(E5#,r)),c),"")))

Working from the inside out, INDEX(E5#,r) gets the team for the current row, and FILTER returns all the names on that team. For the first row, the result is {"Ben";"Eli";"Ida";"Lee"}. The outer INDEX then picks the name in position c. This is how the formula gets around the array of arrays problem: FILTER returns a list, but each cell keeps only one value from the list.
The result from MAKEARRAY is always a rectangle, so a team with fewer names runs out of names before the row ends. When that happens, INDEX returns #REF!, and the IFERROR function replaces the error with an empty string (""), which is why the extra cells look blank.
Both sizes are calculated. ROWS(E5#) creates one row for each team, where E5 contains =SORT(UNIQUE(C5:C16)). To get the number of columns, COUNTIF counts the team for every name, and MAX returns the largest count:
MAX(COUNTIF(C5:C16,C5:C16)) // returns 5
The result is 5 because Red, the largest team, has 5 names. If you add names or teams, the result will resize automatically. To use a separate formula for each group instead, see Multiple matches into separate columns and Multiple matches into separate rows.
Names in a two-way table
In the previous example, each cell keeps one value from a list. Another option is to combine the whole list into one value. In the worksheet below, the goal is to list the staff for each shift and day. SUMIFS and COUNTIFS can create a two-way summary of numbers, but they can't list names. The formula in G5 is:
=MAKEARRAY(ROWS(F5:F6),COLUMNS(G4:K4),LAMBDA(r,c,TEXTJOIN(", ",TRUE,FILTER(B5:B16,(C5:C16=INDEX(F5:F6,r))*(D5:D16=INDEX(G4:K4,c)),""))))

Each cell runs FILTER with two conditions: the shift must match the label for the current row, and the day must match the label for the current column. Multiplying the two conditions works like AND (see Boolean logic). FILTER returns the names that match, or an empty string when there are none, and the TEXTJOIN function joins them into the single value each cell needs. Nobody works the Thursday evening shift, so cell J6 is blank.
This is a general pattern for a two-way summary with any function that returns one result. For example, Excel doesn't have a MEDIANIFS function, but you can replace TEXTJOIN with MEDIAN to calculate a median for each cell:
=MAKEARRAY(ROWS(F5:F6),COLUMNS(G4:K4),LAMBDA(r,c,IFERROR(MEDIAN(FILTER(values,(C5:C16=INDEX(F5:F6,r))*(D5:D16=INDEX(G4:K4,c)))),"")))
Here, values is a range of numbers the same size as the names, and IFERROR returns an empty string when FILTER finds nothing. In Excel 365, the PIVOTBY function can create a similar report with =PIVOTBY(C5:C16,D5:D16,B5:B16,ARRAYTOTEXT,,0,,0). However, by default PIVOTBY sorts the labels A-Z instead of using the order you set up in the worksheet, so there is an advantage to rolling your own solution with MAKEARRAY.
Correlation matrix
A correlation matrix shows how strongly each pair of variables is related. In the worksheet below, the goal is to calculate the correlation between each pair of subjects, based on the test scores for 12 students. For one pair of subjects, the formula is simple: =CORREL(C5:C16,D5:D16) returns 0.97 for Math and Science. However, the CORREL function always returns one result, so =CORREL(C5:G16,C5:G16) just returns 1. The formula in J5 is:
=MAKEARRAY(COLUMNS(C5:G16),COLUMNS(C5:G16),LAMBDA(r,c,CORREL(INDEX(C5:G16,,r),INDEX(C5:G16,,c))))

This example introduces a new idea: r and c both point to the same list. rows and columns are both set to the number of subjects, so every subject meets every other subject. When the row number is left out, INDEX returns an entire column, so INDEX(C5:G16,,r) returns the scores for the subject in the current row and INDEX(C5:G16,,c) returns the scores for the subject in the current column. CORREL compares the two.
The values on the diagonal are 1, because each subject correlates perfectly with itself. In this data, Math and Science move together (0.97), while Math and Art move in opposite directions (-0.97). You could get one row of this matrix with BYCOL, for example =BYCOL(C5:G16,LAMBDA(x,CORREL(x,C5:C16))), but MAKEARRAY returns the whole grid in one formula. You can use the same pattern for any calculation that compares two columns.
Notes
- rows and columns must be whole numbers of 1 or more. A value of 0 or less returns #VALUE!, and so does an empty cell. Decimals like 2.5 and
5/2also return #VALUE!, so wrap a calculated size in ROUNDUP or INT if needed. - rows and columns each take one number, so the result is always a rectangular array. Short rows must be padded, as in List names by group.
- If the cells where the result should spill aren't empty, MAKEARRAY returns #SPILL!. MAKEARRAY also returns #SPILL! inside an Excel Table, because tables don't support spilling formulas, and when the result is too large to fit on the worksheet.
- The LAMBDA must have exactly two parameters. One or three parameters return #VALUE!. The names are up to you, but the first parameter is always the row:
LAMBDA(row,col,row*col). - A LAMBDA that returns an array causes MAKEARRAY to return #CALC!. FILTER is a common cause, because it works in a cell when it finds one match, but returns #CALC! when it finds more than one. Use INDEX to pick one value, or consolidate the values into one result with a function like SUM or TEXTJOIN.
- Functions like COUNTIF and SUMIFS need a range and can't work with an array. If you use one of these functions on an array inside the LAMBDA, MAKEARRAY returns #CALC!. In the same way,
INDEX(data,r,1):INDEX(data,r,c)needs a range and returns #VALUE! on an array. A range stored as a variable with LET works fine. On an array, you can useSUM(TAKE(INDEX(data,r,0),,c))to get a running total. - An error in one cell stays in that cell, and the other results are unaffected.
- INDEX returns 0 for an empty cell. To keep the cell blank, use
IF(x="","",x), wherexis the INDEX formula. You can also usex&"", but this converts numbers to text. - The LAMBDA can't read the results in other cells, so it can't use the value from "the cell above". To carry a value from one cell to the next, use SCAN or REDUCE.
- Each cell gets its own random value when the LAMBDA contains a function like RANDBETWEEN, and the values recalculate like any other random values. However, you don't need MAKEARRAY for a simple random grid. For example,
=CHAR(RANDARRAY(2,3,65,90,TRUE))returns random uppercase letters. See the RANDARRAY function. - MAKEARRAY is available in Excel 2024+ and Excel 365. It isn't available in Excel 2021.