- vector - The array or range to wrap.
- wrap_count - Max values in each column.
- pad_with - [optional] Value to use for unfilled places.
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.
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:
Notice WRAPCOLS outputs values by column, top to bottom, and each column contains 4 rows.
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:
The formula in D10 uses a wrap_count of 4:
Notice values are output top to bottom.
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:
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:
Notice the #N/A errors have been replaced by "x" in the resulting array.
- 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.