Lookup and reference functions
COLUMNS
Known larger differences on 22 of 932 recorded answers
Of 932 recorded answers (932 workbook cells), 22 do not match: 6 differ in kind or value, 16 are refused. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | COLUMNS |
| Bulgarian | COLUMNS |
| Czech | SLOUPCE |
| Danish | KOLONNER |
| German | SPALTEN |
| Greek | COLUMNS |
| English (Australia) | COLUMNS |
| English (United Kingdom) | COLUMNS |
| English (United States) | COLUMNS |
| Spanish | COLUMNS |
| Estonian | COLUMNS |
| Finnish | SARAKKEET |
| French | COLONNES |
| Hebrew | COLUMNS |
| Croatian | COLUMNS |
| Hungarian | OSZLOPOK |
| Indonesian | COLUMNS |
| Italian | COLUMNS |
| Japanese | 列 |
| Korean | 열 |
| Lithuanian | COLUMNS |
| Latvian | COLUMNS |
| Norwegian | KOLONNER |
| Dutch | KOLOMMEN |
| Polish | LICZBA.KOLUMN |
| Portuguese (Brazil) | COLUNAS |
| Portuguese (Portugal) | COLS |
| Romanian | COLUMNS |
| Russian | ЧИСЛСТОЛБ |
| Slovak | COLUMNS |
| Slovenian | COLUMNS |
| Serbian (Latin) | KOLONE |
| Swedish | KOLUMNER |
| Thai | COLUMNS |
| Turkish | SÜTUNSAY |
| Ukrainian | COLUMNS |
| Vietnamese | COLUMNS |
| Chinese (Simplified) | 列 |
| Chinese (Hong Kong) | COLUMNS |
| Chinese (Traditional) | COLUMNS |
Names from Microsoft's support site.
What it does
COLUMNS(array)
COLUMNS(array) returns the number of columns in an array or reference. It is a measurement of
shape, not of content: no cell is read, no value is coerced, and empty cells inside the range
count exactly as much as filled ones.
The distinction worth stating at the top, because the names invite the mistake: COLUMNS counts
columns, COLUMN locates one. COLUMNS(C1:E1) is 3; COLUMN(C1:E1) is the array 3, 4, 5.
Arguments
| Argument | Meaning |
|---|---|
array | An array, an array formula's result, or a reference to a range of cells. Required, exactly one. |
Microsoft's page names this argument array and describes it as an array, an array formula, or
a reference to a range of cells. Two consequences readers trip over:
- A single cell is a 1×1 shape, so
COLUMNS(A1)is 1 rather than an error. - A multi-area reference —
COLUMNS((A1:B2,D1:E2))— has no single width. WhatCOLUMNSreports for a union is not established here, and it is not obvious: the plausible answers (the first area's width, the bounding box's width, an error) are all defensible.
What COLUMNS does with a bare scalar that is neither array nor reference is likewise not
established here.
Try it
Quirks
Result and edge cases
Return kind: Number — a positive integer.
- No coercion of contents. Element kinds are irrelevant. An array of errors has a width.
- Nothing is scanned. Unlike
COUNT-style functions,COLUMNSdoes not visit elements, so an error inside the range does not become the result. This is the practical difference between a shape query and an aggregate: see the scan-policy discussion in coercion and lifting. - A spill anchor (
B1#) has a width that changes when the spill changes;COLUMNS(B1#)is the idiomatic way to ask how wide a dynamic result currently is, and its dependency behaviour is a property of the spill-anchor reference shape rather than of this function. - A structured reference to several table columns has a width that tracks the table.
Errors
Microsoft's page does not publish an error table for COLUMNS. The expected failure is an
argument that is neither an array nor a reference, for which #VALUE! is this family's
conventional code — recorded here as expected, not verified. An error value passed as the
argument propagates under the universal rule in
coercion and lifting; note that this is different from an
error inside the array, which does not affect the count.
How to implement
Notes for implementers
- Answer from the reference, not from the values. Materializing a whole-column reference to
count its columns is correct and catastrophic. The
RefsVisibleInAdapterpreparation profile exists so this function can avoid exactly that. - The multi-area case needs a declared policy, because there is no single right answer. An implementation must choose and record its choice rather than fall out of whatever its reference representation happens to make easy.
- 1×1 arrays. The pipeline's argument preparation collapses a single-cell reference to a
scalar for values-only functions, but
COLUMNSis not values-only, and the unit-array preservation caveat described in the call pipeline is exactly the sort of normalization that can silently change a shape query's answer.
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.
COLUMNS · 7 lines · calc-func/src/catalogue/lookup.rs on GitHubeager(
COLUMNS,
"COLUMNS",
CallableArityShape::exact(1),
&[Parameter::value_or_reference("array")],
columns,
)
columns · 8 lines · calc-func/src/catalogue/lookup.rs on GitHub/// COLUMNS(array): ROWS for columns.
fn columns(
arguments: &[CalcValue],
services: &mut EvalServices<'_>,
) -> Result<CalcValue, FunctionFault> {
let site = Site::new(COLUMNS, services);
Site::finish(extent(&site, &arguments[0], false))
}
Kernels shared with other functions
eagercatalogue/lookuppatterncatalogue/lookupmatchescatalogue/lookupLine::lencatalogue/lookupLine::scancatalogue/lookupreadercatalogue/lookupcell_valuecatalogue/lookuprowscatalogue/lookupcolumnscatalogue/lookupvaluecatalogue/lookupspancatalogue/lookupshapecatalogue/lookupindex_numbercatalogue/lookupindexcatalogue/lookupselectorcatalogue/lookupindexedcatalogue/lookupselectcatalogue/lookuprowcatalogue/lookupcolumncatalogue/lookupposition_ofcatalogue/lookupextentcatalogue/lookupareascatalogue/lookup
Argument and result plumbing
Parameter::value_or_referencecatalogue
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
ROWSis the same measurement on the other axis. Together they give an array's shape.COLUMNlocates rather than counts, and the name similarity is the standing trap.AREAScounts the rectangles in a reference whereCOLUMNSmeasures extent. For a multi-area reference the two questions come apart, which is whyAREASexists.INDEX,OFFSET,TAKE,DROP,WRAPROWSall take width or height arguments that are frequently computed withCOLUMNS.HLOOKUP'srow_index_numandVLOOKUP'scol_index_numare commonly written asCOLUMNS($A$1:B$1)or similar so that the index advances as the formula is copied — one of the oldest idioms in spreadsheet practice, and one thatXLOOKUPremoves the need for.SEQUENCE(1, COLUMNS(a))is the modern way to build an index vector matching an array's width.
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents