Excel function

COLUMNSfunction

Counts the columns in a range.

All versions
=COLUMNS(B2:D6)
A
B
C
D
1
2
3
4
5
6

Drag the corner dots to change array. Make the range wider or narrower. Try breaking it on purpose to see the errors.

Result

3

array
B2:D6Drag the corner dots on the table

The range whose columns you count. Drag a corner to change it.

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

  1. Example 1. Number of columns

    =COLUMNS(B2:D6)

    Columns B, C and D, so 3.

  2. Example 2. Return the last column

    =VLOOKUP(value, table, COLUMNS(table), FALSE)

    Returns the last column of the table.

  3. Example 3. Range shape and column count

    =COLUMNS(A1:Z1)

    Only the width counts, whatever the number of rows.

    FormulaResult
    =COLUMNS(B2:D6)3
    =COLUMNS(A1)1
    =COLUMNS(A:Z)26
    =COLUMNS({1,2,3;4,5,6})3
  4. 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

FAQ

Number of rows?
Use ROWS.
Several ranges?
Give it one range or array.