Lookup and reference functions
WRAPCOLS
Matches all 15 recorded answers
Recorded: 15 workbook cells. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | WRAPCOLS |
| Bulgarian | WRAPCOLS |
| Czech | ZABALSLOUPCE |
| Danish | FOLDKOLONNER |
| German | WRAPCOLS |
| Greek | WRAPCOLS |
| English (Australia) | WRAPCOLS |
| English (United Kingdom) | WRAPCOLS |
| English (United States) | WRAPCOLS |
| Spanish | AJUSTARCOLS |
| Estonian | WRAPCOLS |
| Finnish | RIVITÄSAR |
| French | ORGA.COLS |
| Hebrew | WRAPCOLS |
| Croatian | WRAPCOLS |
| Hungarian | OSZLOPTÖRDELÉS |
| Indonesian | WRAPCOLS |
| Italian | WRAPCOLS |
| Japanese | WRAPCOLS |
| Korean | WRAPCOLS |
| Lithuanian | WRAPCOLS |
| Latvian | WRAPCOLS |
| Norwegian | WRAPCOLS |
| Dutch | OMLOOP.KOLOMMEN |
| Polish | ZAWIŃ.KOLUMNY |
| Portuguese (Brazil) | WRAPCOLS |
| Portuguese (Portugal) | MOLDARCOLS |
| Romanian | WRAPCOLS |
| Russian | СВЕРНСТОЛБЦ |
| Slovak | WRAPCOLS |
| Slovenian | WRAPCOLS |
| Serbian (Latin) | WRAPCOLS |
| Swedish | BRYTKOLUMN |
| Thai | WRAPCOLS |
| Turkish | SÜTUNSAR |
| Ukrainian | WRAPCOLS |
| Vietnamese | WRAPCOLS |
| Chinese (Simplified) | WRAPCOLS |
| Chinese (Hong Kong) | WRAPCOLS |
| Chinese (Traditional) | WRAPCOLS |
Names from Microsoft's support site.
What it does
WRAPCOLS(vector, wrap_count, [pad_with])
WRAPCOLS turns a vector into a rectangle, filling it column by column.
Given a vector of N elements and a wrap count k, the result is an array of k rows and
⌈N / k⌉ columns: the first k elements become column 1 (top to bottom), the next k become
column 2, and so on. If N is not a multiple of k, the final column is short and its
remaining cells are filled with pad_with.
Concretely, WRAPCOLS({1,2,3,4,5}, 3) gives
1 4
2 5
3 #N/A
Two consequences of the definition are worth stating because the argument's name invites the opposite reading:
wrap_countis the column height, not the number of columns. It is "how many values per column", and the number of columns is derived. Reading it as "make mekcolumns" gives a transposed, wrongly sized answer.- The result's width grows with the input. Unlike every other function in this family, the output shape depends on the input's length rather than on its shape.
When wrap_count is greater than or equal to N, everything fits in one column and the result
is a single column array — no padding, no second column.
Arguments
Microsoft documents WRAPCOLS(vector, wrap_count, [pad_with]).
vector — required. Must be genuinely one-dimensional: a single row or a single column. A
rectangular array is documented as #VALUE!, not as something to flatten first. (If you want
flattening, that is TOCOL.)
wrap_count — required. The maximum number of values in each column, so the result's row
count. Documented as #NUM! when less than 1.
pad_with — optional, default #N/A. The value placed in the trailing cells of the
final column.
The default deserves the same note as VSTACK's: padding with an error is a deliberate
choice that makes the padding self-announcing. Passing pad_with explicitly — "", 0, or a
placeholder — is the usual remedy, and unlike the IFERROR-wrapping trick it does not also
swallow genuine #N/A values from the data.
Try it
Quirks
Result and edge cases
The return kind is a two-dimensional array of wrap_count rows.
- Exact multiples produce no padding at all.
wrap_count ≥ Nproduces a single column, unpadded.wrap_count = 1produces a single row — every element in its own column. This is a transposition of the input when the input is a column, and a no-op when it is a row.- A one-element vector produces a 1×1 array, which must stay array-shaped.
pad_withis not coerced to the vector's type; it is placed as given, and it may be text in an otherwise numeric array.- Blanks and errors inside
vectorare ordinary elements and are placed unchanged, which means a genuine#N/Ain the data is indistinguishable from default padding in the result. - Dynamic-array publication and
#SPILL!are host-side adaptation, described in the call pipeline.
Errors
Documented by Microsoft:
| Error | Documented condition |
|---|---|
#VALUE! | vector is not a one-dimensional array |
#NUM! | wrap_count is less than 1 |
#N/A | Placed in each cell of the return array that has no result — the default padding |
The third row is padding rather than failure, and a test oracle must not treat an #N/A in the
result as an error outcome.
How to implement
Notes for implementers
- The output shape is
wrap_count × ⌈N / wrap_count⌉. Deriving the width by division needs the ceiling, and the last column's fill boundary needs the remainder — two places to be off by one. - Column-major fill is the defining behaviour; the twin function's row-major fill must not be reachable by a shared code path with a flipped flag unless the shape derivation flips too.
pad_withdefaults to#N/A, an error value, and must be placed verbatim without coercion.- One-dimensionality is validated, not repaired: a rectangular input is
#VALUE!.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.
WRAPCOLS · 3 lines · calc-func/src/catalogue/arrays.rs on GitHub15 wrapcols_fn "WRAPCOLS" (2, 3) [R "vector", V "wrap_count", V "pad_with"] |s, a, sv| {
run(s, a, sv, k::eval_wrapcols_prepared)
}
eval_wrapcols_prepared · 26 lines · calc-func/src/ported/dynamic_array_reshape_family.rs on GitHubpub fn eval_wrapcols_prepared(
args: &[CalcValue],
) -> Result<CalcValue, DynamicArrayReshapeEvalError> {
let wrap_count = wrap_count(&args[1])?;
match args[0].core_ref() {
CoreRef::Number(_) | CoreRef::Text(_) | CoreRef::Logical(_) | CoreRef::Error(_) => {
return Ok(args[0].clone());
}
CoreRef::Array(_) | CoreRef::Reference(_) | CoreRef::Missing | CoreRef::Empty => {}
}
let source = wrap_vector(&args[0])?;
let pad_cell = args
.get(2)
.map(scalar_cell)
.unwrap_or(CalcValue::error(WorksheetErrorCode::NA));
let flat = flatten_cells(&source, false);
let rows = wrap_count.min(flat.len());
let cols = flat.len().div_ceil(rows);
let mut grid = vec![pad_cell.clone(); rows * cols];
for (index, cell) in flat.into_iter().enumerate() {
let row = index % rows;
let col = index / rows;
grid[row * cols + col] = cell;
}
build_array(rows, cols, grid)
}
Kernels shared with other functions
preparedcatalogue/arraysprepared_onecatalogue/arraysresultcatalogue/arraysruncatalogue/arrayscoerce_prepared_to_numberported/dynamic_array_reshape_familyscalar_cellported/dynamic_array_reshape_familymaterialize_array_argported/dynamic_array_reshape_familyshapeported/dynamic_array_reshape_familygetported/dynamic_array_reshape_familyparse_integerported/dynamic_array_reshape_familyparse_positive_integerported/dynamic_array_reshape_familybuild_arrayported/dynamic_array_reshape_familyflatten_cellsported/dynamic_array_reshape_familywrap_countported/dynamic_array_reshape_familywrap_vectorported/dynamic_array_reshape_familymap_dynamic_array_reshape_error_to_wsported/dynamic_array_reshape_family
Argument and result plumbing
No implementation has been published with a Handbook test suite for this function.
Version differences
No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.
Alternatives
Relationships
WRAPROWSis the twin, filling row by row instead of column by column, withwrap_countas the row width. The two produce transposed-looking but genuinely different arrangements of the same elements, and choosing the wrong one is the most common mistake in this pair.TOCOL/TOROWare the inverse operation — rectangle to vector — with the same self-announcing relationship to structure.EXPANDpads an existing array to a target size with a chosen filler;WRAPCOLSpads as a side effect of reshaping.SEQUENCEgenerates a rectangle of consecutive numbers directly, which is often what a reader reaching forWRAPCOLS(SEQUENCE(n), k)actually wants.INDEXwith computed row and column arithmetic is the pre-dynamic-array way of doing this, and is still what you will find in older workbooks.
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents