Lookup and reference functions

ROWS

Known larger differences on 22 of 975 recorded answers

Of 975 recorded answers (975 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
LanguageName in Excel
ArabicROWS
BulgarianROWS
CzechROWS
DanishRÆKKER
GermanROWS
GreekROWS
English (Australia)ROWS
English (United Kingdom)ROWS
English (United States)ROWS
SpanishFILAS
EstonianROWS
FinnishRIVIT
FrenchROWS
HebrewROWS
CroatianROWS
HungarianROWS
IndonesianROWS
ItalianROWS
JapaneseROWS
KoreanROWS
LithuanianROWS
LatvianROWS
NorwegianROWS
DutchROWS
PolishROWS
Portuguese (Brazil)ROWS
Portuguese (Portugal)ROWS
RomanianROWS
RussianROWS
SlovakROWS
SlovenianROWS
Serbian (Latin)ROWS
SwedishROWS
ThaiROWS
TurkishSATIRSAY
UkrainianROWS
VietnameseROWS
Chinese (Simplified)ROWS
Chinese (Hong Kong)ROWS
Chinese (Traditional)ROWS

Names from Microsoft's support site.

What it does

ROWS(array)

ROWS returns the number of rows in its argument, as a scalar number.

For a reference, that is the row span of the referenced area: ROWS(A5:C9) is 5. For a single cell it is 1. For an array — a literal, a dynamic-array result, or the value returned by another function — it is the array's first dimension: ROWS({1,2;3,4}) is 2.

The whole function is that one sentence, which is why it is worth being exact about the two things it is not:

  • It is not ROW. ROW reports which rows; ROWS reports how many. ROW(A5:A8) is the array {5;6;7;8}; ROWS(A5:A8) is 4.
  • It does not count populated rows. ROWS measures the shape of the reference, not its contents. A range with three blank rows in the middle still has its full row count. Counting data is COUNTA's job, and mistaking one for the other is the usual source of off-by-many errors in "dynamic range" formulas.

The function's real importance is structural: it is how a formula asks about the shape of something it was handed. ROWS and COLUMNS are the shape-introspection primitives that make generic array formulas possible, and they are what a LAMBDA uses to size its own work.

Arguments

array — required, exactly one. A reference or an array whose row count is wanted. Both argument kinds are admissible: the argument name in the signature says array, but a reference is equally valid, and in practice references are the common case.

Try it

Input cells (optional)

Example: {"B2": 3, "B3": 4}. A1 holds the formula. Other cells need values before a formula can read them.

Enter a formula, then calculate.

Runs locally in your browser with OneCalc. Its answer may differ from Excel. Use English function names and commas between arguments.

Quirks

Result and edge cases

The return kind is always a scalar number — never an array, whatever the argument's shape.

  • Whole-column references return the grid's full row count, which differs between the modern grid and an .xls-compatibility workbook. ROWS(A:A) is a version-scoped answer.
  • Multi-area references are not described by the documentation, and the Handbook has not verified what ROWS does with a union.
  • Reference resolution, and the fact that ROWS inspects the reference rather than its values, are covered in the call pipeline.

Errors

Microsoft's documentation for ROWS names no error values. Observable failures come from elsewhere: a #REF! reference propagates, and an argument of the wrong kind is refused at entry.

Whether an error value passed directly (ROWS(#N/A)) propagates or is treated as a 1×1 shape is not documented, and the Handbook has not verified it.

How to implement

Notes for implementers

  • The answer must be a scalar, always. Returning a 1×1 array is wrong in a way that will not show up until the result is nested inside something shape-sensitive.
  • The argument must not be dereferenced. ROWS of a whole column must not require reading a million cells.
  • The 1×1-array-versus-scalar distinction is load-bearing. Argument preparation normally collapses a single-cell reference to a scalar; ROWS needs the shape that existed before that collapse, or it needs the reference itself.
  • Whole-column and whole-row answers are grid-size dependent and therefore workbook- compatibility dependent. Hard-coding the modern grid's row count makes the function silently wrong on legacy workbooks.

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.

ROWS · 7 lines · calc-func/src/catalogue/lookup.rs on GitHub
eager(
    ROWS,
    "ROWS",
    CallableArityShape::exact(1),
    &[Parameter::value_or_reference("array")],
    rows,
)
rows · 10 lines · calc-func/src/catalogue/lookup.rs on GitHub
/// ROWS(array): the rows of a reference's single area or of an array; a single value has one; an
/// error is the result; a reference of several areas is #REF!, and a blank or omitted argument
/// #VALUE!.
fn rows(
    arguments: &[CalcValue],
    services: &mut EvalServices<'_>,
) -> Result<CalcValue, FunctionFault> {
    let site = Site::new(ROWS, services);
    Site::finish(extent(&site, &arguments[0], true))
}

Kernels shared with other functions

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

  • COLUMNS is the transpose: the horizontal extent, same shape of answer.
  • ROW is the coordinate function, not the count function — see above.
  • SEQUENCE(ROWS(x)) is the modern idiom for "one index per row of x", replacing ROW(INDIRECT(...)).
  • TRIMRANGE answers the question people often ask ROWS by mistake: how big is the populated part of this range.

Named variants

No named variants are recorded yet.

Suggest a correction or contribute an implementation · For agents