What is the COLUMNS function?
=COLUMNS(array)COLUMNS counts how many columns a range has.
Use it to point VLOOKUP at the last column of a table or to check a range's size.
COLUMNS makes a number that grows 1, 2, 3… as a formula is copied to the right, or points at the last column of a table even when columns are added. It looks only at the shape of the range, so blank cells do not change the result.
Arguments
- array
- The range whose columns you count.
COLUMNS examples
Example 1. Number of columns
=COLUMNS(B2:D6)Columns B, C and D, so 3.
Example 2. Return the last column
=VLOOKUP(value, table, COLUMNS(table), FALSE)Returns the last column of the table.
Example 3. Range shape and column count
=COLUMNS(A1:Z1)Only the width counts, whatever the number of rows.
Formula Result =COLUMNS(B2:D6) 3 =COLUMNS(A1) 1 =COLUMNS(A:Z) 26 =COLUMNS({1,2,3;4,5,6}) 3 Example 4. Column index that grows to the right
=VLOOKUP($A2, $F$2:$I$10, COLUMNS($F$2:G2), FALSE)Copied right, COLUMNS gives 2, 3, 4, so the 2nd, 3rd and 4th columns come back in turn.
Common mistakes
Confusing it with COLUMN
COLUMN is a position; COLUMNS is a count.
Expecting only filled cells
Empty cells count too.
Where the $ goes
Without $ on the left end of COLUMNS($F$2:G2), the whole range moves when copied and the number stops growing.
FAQ
- Number of rows?
- Use ROWS.
- Several ranges?
- Give it one range or array.