Google Sheets function · Lookup
COLUMNS in Google Sheets: syntax and examples
COLUMNS counts the columns in a range or array. It returns a size, not a position. Use it to size formulas that must follow a table as it grows, for example as the index in VLOOKUP or INDEX.
Syntax
COLUMNS(range)
Arguments
| Argument | Type | Required | What it does |
|---|---|---|---|
range | range | yes | The range or array to count columns in. |
Examples
The examples use this table, starting in A1:
| a | b | c | d |
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
=COLUMNS(A1:D3)Result: 4
A block four columns wide.
Run in a Google Sheet (English US locale) on .
=COLUMNS(B:C)Result: 2
Whole columns count too: B and C make two.
Run in a Google Sheet (English US locale) on .
=COLUMNS(C2)Result: 1
One cell is one column, not the number 3. COLUMN would return 3.
Run in a Google Sheet (English US locale) on .
=COLUMNS({1, 2, 3})Result: 3
An inline array with three values in a row.
Run in a Google Sheet (English US locale) on .
=INDEX(A2:D3, 2, COLUMNS(A2:D3))Result: 8
The last column of row 2, without hard-coding 4.
Run in a Google Sheet (English US locale) on .
Common errors
- COLUMNS counts, COLUMN gives a position. COLUMNS(C2) is 1, while COLUMN(C2) is 3.
- It takes exactly one argument. A second one returns #N/A.
- A whole-column reference such as B:C counts every column in it.
- In a locale that uses ";" and "\", an inline array written with commas returns #ERROR!.
Compared with Excel
Same syntax in Excel.