COLUMNS Function (LibreOffice Calc)
The COLUMNS function returns the number of columns in a given range or array. It is used in dynamic formulas, array construction, indexing, and scalable lookup logic.
Verification status: Consult the documentation, examples and any stated test scope below. How formula examples are checked
Availability and version history
- Introduced: Documented by LibreOffice 26.8.1.1; original introduction not established.
- Availability: Supported in LibreOffice 26.8.1.1, verified against its function registry. This identifies a supported release, not a final working version.
- Scope: Desktop Calc, using the English function name. Availability in other spreadsheet applications is separate.
- Checked: 2026-10-14 — function reference; versioned support. Documentation/source check; not a new native test. Existing example-specific test claims below retain their stated scope.
What the COLUMNS Function Does
- Counts the number of columns in a range or array
- Works with static ranges and dynamic arrays
- Useful for INDEX/MATCH, OFFSET, and array‑driven formulas
- Helps build scalable, correction‑proof spreadsheet logic
Syntax
COLUMNS(reference)
Arguments
- reference:
A range or array whose number of columns will be counted.
Basic Examples
Count columns in a range
=COLUMNS(A1:D10)
→ 4
Count columns in a single column
=COLUMNS(B1:B100)
→ 1
Using a dynamic array
=COLUMNS(FILTER(A1:D100; A1:A100>0))
Using an array literal
=COLUMNS({1,2,3})
→ 3
Advanced Examples
Dynamic INDEX selection
=INDEX(A1:Z1; COLUMNS(A1:D1))
→ returns the last column in A1:D1
Create a dynamic header count
="Total Columns: " & COLUMNS(A1:Z1)
Combine with OFFSET for scalable ranges
=SUM(OFFSET(A1; 0; 0; 1; COLUMNS(A1:D1)))
Use with MATCH to validate lookup ranges
=IF(MATCH("Price"; A1:D1; 0) <= COLUMNS(A1:D1); "OK"; "Out of Range")
Generate a dynamic sequence of column numbers
=COLUMN(A1:INDEX(1:1; COLUMNS(A1:D1)))
Use with CHOOSECOLS for dynamic extraction
=CHOOSECOLS(A1:Z10; SEQUENCE(1; COLUMNS(A1:D1)))
Edge Cases and Behavior Details
COLUMNS returns:
- A single integer
- Always ≥ 1 for valid ranges
Behavior details
- Works with ranges, arrays, and array formulas
- Does not count rows
- Does not evaluate content, only structure
- Errors inside the range do not affect the result
- Invalid references propagate errors
Invalid reference → Err:502
Common Errors and Fixes
Err:502 — Invalid argument
Cause:
- Reference is malformed
- Reference is text that cannot be parsed
Fix:
- Use INDIRECT for text references
- Validate cell/range references
Unexpected result
Cause:
- Using COLUMNS on a spilled array without understanding its width
Fix:
- Inspect the array with the formula bar
- Use WRAPCOLS/WRAPROWS (Excel) equivalents if needed
Best Practices
- Use COLUMNS to build scalable, correction‑proof formulas
- Combine with INDEX for dynamic column selection
- Use with OFFSET for dynamic range sizing
- Use with MATCH to validate lookup ranges
- Pair with COLUMN for array‑driven logic
Related Patterns and Alternatives
- COLUMN — returns the column index of a reference
- ROWS / ROW — row equivalents
- INDEX — extract values by row/column
- MATCH — find column positions
- OFFSET — dynamic range shifting
- CHOOSECOLS — extract specific columns
By mastering COLUMNS, you can build robust, scalable, and dynamic spreadsheet logic in LibreOffice Calc.
Reproducible example (tested in LibreOffice Calc)
This standalone example was calculated in LibreOffice Calc 25.2.3.2 and matched the expected value. It is a practical cross-check of one usage, not proof that every example elsewhere on this page is correct.
Use this small practice sheet for the ranges referenced in the formula:
| Row | A (Quantity) | B (Amount) | C (Category) |
|---|---|---|---|
| 1 | 1 | 10 | apple |
| 2 | 2 | 20 | pear |
| 3 | 3 | 30 | apple |
| 4 | 4 | 40 | pear |
| 5 | 5 | 50 | apple |
=COLUMNS(A1:C5)
Expected result: 3.
Count the number of columns in a selected range.
If the result differs, check the referenced cells, argument separators and number formatting. For more information, consult the LibreOffice Calc official help.