Exceljet

Quick, clean, and to the point

Excel WRAPCOLS Function

Excel WRAPCOLS function
Summary 

The Excel WRAPCOLS function converts a one-dimensional array into a two-dimensional array by wrapping values into separate columns. The length of each column is given as the wrap_count argument: when the count is reached, WRAPCOLS starts a new column.

Purpose 
Wrap array into columns
Return value 
Array wrapped by column
Syntax 
=WRAPCOLS (vector, wrap_count, [pad_with])
Arguments 
  • vector - The array or range to wrap.
  • wrap_count - Max values in each column.
  • pad_with - [optional] Value to use for unfilled places.
Version 
Usage notes 

The WRAPCOLS function converts a one-dimensional array into a two-dimensional array by wrapping values into separate columns. The length of each column is given as the wrap_count argument: when the count is reached, WRAPCOLS starts a new column.

The WRAPCOLS function takes three arguments: vector, wrap_count, and pad_with. Vector and wrap_count are both required. Vector must be a one-dimensional array or range. Wrap_count is a number that represents the length of each column. The final argument, pad_with, is an optional value to use if there are empty spots in the last column. If no value is supplied for pad_with, WRAPCOLS will return an #N/A error after all values in vector have been used. You can override this behavior by providing a custom value for the pad_with argument.

Basic usage

WRAPCOLS outputs values "by column", working top to bottom, left to right. When wrap_count has been reached, WRAPCOLS starts a new column. In the worksheet below, the goal is to wrap the range C2:J2 into columns that each contain 4 values. The formula in B5 is:

=WRAPCOLS(C2:J2,4)

WRAPCOLS function - basic usage

Notice WRAPCOLS outputs values by column, top to bottom, and each column contains 4 rows.

Wrap count

Wrap_count represents the maximum number of values in each column. Once the count has been reached, WRAPCOLS starts a new column. In the screen below, you can see how this works. The formula in D3 uses a wrap_count of 3:

=WRAPCOLS(B3:B14,4)

The formula in D10 uses a wrap_count of 4:

=WRAPCOLS(B3:B14,3)

WRAPCOLS - wrap count behavior

Notice values are output top to bottom.

Padding

If no value is supplied for pad_with, WRAPCOLS will return an #N/A error after all values in the source array have been accounted for. You will see these errors appear in the last column when the total number of items in the source array is not evenly divisible by the wrap_count. You can override this behavior by providing a custom value for the pad_with argument. The formula in D3 shows default behavior. No value for pad_with has been provided:

=WRAPCOLS(B3:B12,4)

The input range contains only 10 cells, which is not evenly divisible by a wrap_count of 4. As a result, the last 2 cells return #N/A. The formula in D10 supplied "x" for pad_with:

=WRAPCOLS(B3:B12,4,"x")

WRAPCOLS - padding example

Notice the  #N/A errors have been replaced by "x" in the resulting array.

Notes

  • WRAPCOLS will return a #VALUE! error if vector is not a one-dimensional array or range.
  • Wrap_count indicates the size of each column not the number of columns.

Download 100+ Important Excel Functions

Get over 100 Excel Functions you should know in one handy PDF.