Summary

The Excel WRAPROWS function converts a single row or column into a table by wrapping values into rows of a given length. It is useful for turning a long list into one row per record or group, and it pairs naturally with BYROW to calculate a result for each group.

Purpose
Wrap array into rows
Return value
Array wrapped by row
Syntax
=WRAPROWS(vector, wrap_count, [pad_with])
  • vector - The single row or column to wrap.
  • wrap_count - The number of values in each row.
  • pad_with - [optional] Value to use for unfilled places in the last row.

Using the WRAPROWS function

The WRAPROWS function converts a single row or column into a table by wrapping values into rows. Rows are filled from left to right, and the length of each row is provided as the wrap_count argument. When the count is reached, WRAPROWS starts a new row. The result spills onto the worksheet as a 2D array.

The name WRAPROWS can be confusing, because it suggests that the function wraps input provided as one or more rows. The actual meaning is "wrap into rows": WRAPROWS wraps a vector (a single row or column) into rows. The WRAPCOLS function works the same way, but it wraps the vector into columns.

WRAPROWS vs WRAPCOLS diagram - WRAPROWS wraps values into rows, WRAPCOLS wraps values into columns

A common reason to use WRAPROWS is a list that contains records or groups in a fixed pattern, like a column of contacts pasted from a report, where every three cells hold a name, a department, and a phone extension. WRAPROWS turns the list into a table with one record per row.

Wrapping a column or row into a grid is useful on its own, but there is a more subtle and powerful benefit that may not be obvious at first glance: each row represents a group of n items. After WRAPROWS returns the grid, other functions can work on the groups one at a time. For example, BYROW can total each group, and TAKE or CHOOSECOLS can extract specific columns to get every nth item. See below for examples.

WRAPROWS wraps a list of values into rows. It has nothing to do with wrapping text inside a cell. For that, see How to wrap text in cells in Excel.

Key features

  • Turns a single column or row into a table, filling each row from left to right, then starting the next row.
  • wrap_count is the length of each row (the number of columns), not the number of rows.
  • When the values don't divide evenly, the last row is padded with #N/A unless you supply pad_with.
  • Needs a single row or column. A 2D range returns #VALUE!, so flatten with TOCOL first if needed.
  • Returns an array, so functions like BYROW, TAKE, and CHOOSECOLS can work with the result directly.
  • The WRAPCOLS function does the same job by column.

Table of contents

Basic examples

WRAPROWS needs a list and a row length, provided as wrap_count:

=WRAPROWS(range,3) // rows of 3 values
=WRAPROWS(range,4) // rows of 4 values

When the number of values doesn't divide evenly by wrap_count, WRAPROWS fills the empty places in the last row with #N/A. To override this value, provide your own value for pad_with:

=WRAPROWS(range,3,"") // pad with nothing
=WRAPROWS(range,3,"x") // pad with "x"

Wrap count example

The wrap_count argument sets the number of values in each row. When the count is reached, WRAPROWS starts a new row. In the worksheet below, column B contains the 12 letters A to L. The formula in D5 uses a wrap_count of 4:

=WRAPROWS(B5:B16,4)

The formula in D11 uses a wrap_count of 3:

=WRAPROWS(B5:B16,3)

WRAPROWS example - wrap count

With a wrap_count of 4, WRAPROWS returns 3 rows of 4 letters. With a wrap_count of 3, it returns 4 rows of 3 letters. In both cases, WRAPROWS fills each row from left to right before it starts the next row, and it works out the number of rows on its own.

Padding example

When the number of values doesn't divide evenly by wrap_count, the last row comes up short, and WRAPROWS fills the empty places with #N/A errors. In the worksheet below, column B contains the 10 letters A to J. The formula in D5 wraps the letters into rows of 4 with no value for pad_with:

=WRAPROWS(B5:B14,4)

Because 10 doesn't divide evenly by 4, the last row has only 2 letters, and the last 2 places return #N/A. To override this behavior, provide a value for pad_with. The formula in D11 uses "x":

=WRAPROWS(B5:B14,4,"x")

WRAPROWS example - padding

Notice the #N/A errors have been replaced by "x" in the last row.

WRAPROWS vs WRAPCOLS

The WRAPCOLS function works like WRAPROWS, but it wraps values into columns instead of rows. In the worksheet below, column B contains the numbers 1 to 12. The formula in D5 wraps the numbers with WRAPROWS:

=WRAPROWS(B5:B16,4)

The formula in D11 wraps the same numbers with WRAPCOLS:

=WRAPCOLS(B5:B16,4)

WRAPROWS example - WRAPROWS vs WRAPCOLS

WRAPROWS fills each row from left to right before it starts the next row, so the result is 3 rows of 4 numbers. WRAPCOLS fills each column from top to bottom before it starts the next column, so the result is 4 rows of 3 numbers. In other words, wrap_count is the length of each row in WRAPROWS and the length of each column in WRAPCOLS.

Convert a list into a table

A common problem in Excel is a list of records in a single column, one field per cell. This often happens when you copy a report from a PDF or a web page. In the worksheet below, column B contains contact information for 4 people. Each person takes up three cells: Name, Department, and Ext. The goal is to convert the list into a table with one row per person. The formula in D5 is:

=WRAPROWS(B5:B16,3)

WRAPROWS example - convert a list into a table

WRAPROWS reads the 12 values in B5:B16 and starts a new row after every third value. The result is a table of 4 rows and 3 columns that spills into D5:F8. Notice that wrap_count is 3 because each record has three fields, and WRAPROWS works out the number of rows on its own: 12 values / 3 = 4 rows. For a similar example that uses an older formula, see Unwrap column into fields.

Arrange a list in rows

WRAPROWS doesn't need a list of records. You can use it to lay out any list in rows, for example, to fit a long list of names onto a printed page or a seating chart. In the worksheet below, there are 10 names in column B, and the goal is to arrange the names in rows of 4. The formula in D5 is:

=WRAPROWS(B5:B14,4)

WRAPROWS example - arrange a list in rows

WRAPROWS returns 3 rows of 4 values. The last row has only 2 names, so WRAPROWS fills the two empty places with #N/A, as in the Padding example above. For a list of names, an empty string ("") is a better choice for pad_with, since it leaves the extra places empty. The formula in I5 is:

=WRAPROWS(B5:B14,4,"")

You can use any value for pad_with: a number like zero, a text value like "-", or an empty string, as above. The next example shows why the choice can matter when you calculate with the result.

Sum every n rows

Once each group of values is in its own row, other functions can work with the groups one at a time. In the worksheet below, column C contains sales for 15 days, 5 days per week. The goal is to calculate a total for each week. The formula in F5 is:

=BYROW(WRAPROWS(C5:C19,5),SUM)

WRAPROWS example - sum every n rows

Working from the inside out, WRAPROWS wraps the 15 amounts into 3 rows of 5, one row per week:

{45,70,20,0,85;42,35,30,50,45;25,105,80,40,35}

Then the BYROW function runs the SUM function on each row and returns one total per week:

=BYROW({45,70,20,0,85;42,35,30,50,45;25,105,80,40,35},SUM) // returns {220;202;285}

The SUM function is given to BYROW by name only. This short form is called an eta lambda. To get the largest value or the count for each week instead, swap in MAX or COUNT the same way.

What happens when the last week is short? If the range is C5:C17, the last row has only 3 values, so WRAPROWS pads it with two #N/A errors, and SUM returns #N/A for that week. To fix the problem, provide a value for pad_with:

=BYROW(WRAPROWS(C5:C17,5,0),SUM) // returns {220;202;210}

For a sum, padding with zero or an empty string gives the same result. For an average, they are different. AVERAGE counts zeros, but it ignores empty strings in an array. With zero for pad_with, the last week's average is 210 / 5 = 42, which is wrong. With an empty string, the average is 210 / 3 = 70:

=BYROW(WRAPROWS(C5:C17,5,""),AVERAGE) // last week is 70
=BYROW(WRAPROWS(C5:C17,5,0),AVERAGE) // last week is 42

So pad with an empty string when you plan to average the groups. For more details, see Sum every n rows, which also averages sensor readings in groups.

Get every nth value

WRAPROWS also makes it easy to pick values from a list in a repeating pattern, like every 3rd value. In the worksheet below, column B contains the numbers 1 to 12, and the goal is to get every 3rd value. The formula in D5 is:

=TAKE(WRAPROWS(B5:B16,3),,-1)

WRAPROWS example - get every nth value

The trick is to see that every 3rd value lands in the last column when the list is wrapped into rows of 3:

{1,2,3;4,5,6;7,8,9;10,11,12}

The TAKE function then returns the last column. The rows argument is left empty, and -1 for columns means one column from the end. The result is {3;6;9;12}. To get the first value in each group of 3 instead, use 1 for columns. The formula in F5 is:

=TAKE(WRAPROWS(B5:B16,3),,1) // returns {1;4;7;10}

To keep more than one column, use the CHOOSECOLS function. For example, with the contact list from Convert a list into a table, the formula below keeps Name and Ext and drops Department:

=CHOOSECOLS(WRAPROWS(B5:B16,3),1,3)

For other ways to solve this problem, see Copy value from every nth row and Filter every nth row.

Records separated by blank lines

In the worksheet below, each contact has three lines, followed by an empty cell. The goal is to create a table with one row per contact. You could wrap the list by 4, since each record plus its blank line takes up 4 cells, but that creates a fourth column of zeros, because empty cells become zero in a formula. A better approach is to remove the empty cells with the TOCOL function before wrapping, like this:

=WRAPROWS(TOCOL(B5:B15,1),3)

WRAPROWS example - records separated by blank lines

TOCOL converts a range to a single column, which has no effect in this case, since B5:B15 is already a single column. However, setting ignore to 1 causes TOCOL to ignore (and therefore remove) the empty cells, so TOCOL returns just the 9 values, and WRAPROWS wraps them into rows of 3.

The same TOCOL step solves another problem: WRAPROWS only accepts a single row or column, and it returns #VALUE! if you give it a 2D range. To wrap a range with more than one column, flatten it with TOCOL first: =WRAPROWS(TOCOL(range),3).

Note: this approach only works when every record has the same number of lines. WRAPROWS can't wrap records of different lengths, because wrap_count is a single number.

Make random teams

WRAPROWS is often the last step in a formula that works on a list first. In the worksheet below, the goal is to divide the 10 names in column B into 4 random teams, one team per column. The formula in D5 is:

=WRAPROWS(SORTBY(B5:B14,RANDARRAY(ROWS(B5:B14))),4,"")

WRAPROWS example - make random teams

Working from the inside out, the RANDARRAY function creates 10 random numbers, one for each name. The SORTBY function sorts the names by the random numbers, which shuffles the list. Finally, WRAPROWS wraps the shuffled names into rows of 4, so each column is a team. WRAPROWS deals the names across the columns like a deck of cards, so the teams are as even as possible: Teams 1 and 2 get 3 people, and Teams 3 and 4 get 2. The last row has only 2 names, so pad_with is an empty string, as in Arrange a list in rows.

RANDARRAY is a volatile function, so the teams change every time the worksheet recalculates. To keep a set of teams, copy the result and paste it as values. To assign a random group to each person instead of listing teams in columns, see Randomly assign people to groups.

Notes

  • WRAPROWS returns #VALUE! if vector is not a single row or column. Flatten a 2D range with TOCOL or TOROW first. TOCOL reads the range by row by default, or by column when scan_by_column is TRUE, and that order carries through to the wrapped result.
  • wrap_count must be at least 1, or WRAPROWS returns #NUM!. A decimal wrap_count is truncated, so 2.9 wraps by 2.
  • If vector has no more values than wrap_count, WRAPROWS returns one row with just those values, and there is no padding. For example, 3 values wrapped by 4 return 3 values.
  • Empty cells in vector appear as zeros in the result on the worksheet, which is standard behavior for Excel formulas.
  • Every group must have the same number of values. WRAPROWS can't wrap records of different lengths.
  • WRAPROWS returns #SPILL! if something blocks the spill range.
  • WRAPROWS is available in Excel 2024+ and Excel 365. It is not available in Excel 2021.

WRAPROWS is one of over 50 new functions in Excel, available in Excel 2024+ and Excel 365. See New Excel Functions for a complete list.

Support Exceljet

Many websites (including Exceljet) have lost over half their traffic in the past year because of the crushing impact of AI on web searches. Exceljet is still at it, publishing free content each week. If you find Exceljet helpful, you can support the site and go ad-free with the Exceljet Lifetime Pass. One payment, no subscription, and ads are gone forever. Plus, you get our Excel Shortcuts video course as a thank you.

Get the Lifetime Pass

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.