Skip to content

COLUMNS

Returns the number of columns in a range or array, whether or not the cells are filled. Use it to count items across, average across a row or count the parts of split text.

Syntax

=COLUMNS()

Lookup and reference

Every version of Excel, including Microsoft 365, Excel 2024, 2021, 2019, 2016 and earlier, Excel for the web and the mobile apps.

Try it

Edit the formula in A4 or change the inputs. The sheet recalculates as you type.

A4
A
B
C
D
E
F
G
H
1
Region
Q1
Q2
Q3
Q4
2
3
Columns in B1:E1
4
4

A4 =COLUMNS(B1:E1) returns 4

How COLUMNS works

COLUMNS returns how many columns a range or array has. =COLUMNS(B2:G2) returns 6, whether those cells are full, empty or a mix. It measures the shape of the range, and that is the difference between COLUMNS and the counting functions.

The argument

array is a cell range, an array constant such as {1,2,3}, or the result of a formula that returns an array. For a single cell, COLUMNS returns 1.

COLUMNS doesn't look at what is in the cells. To count filled cells use COUNTA, to count numbers use COUNT, and to count blanks use COUNTBLANK. Use COLUMNS when you want the width of the block itself.

What it is good for

  • Counting the parts of split text. In Microsoft 365 and Excel 2021 or later, =COLUMNS(TEXTSPLIT(A2, ",")) counts how many comma-separated items a cell holds. For red,green,blue it returns 3.
  • Counting the columns of a dynamic array result. =COLUMNS(UNIQUE(A2:H2, TRUE)) counts distinct values across a row.
  • Averaging across a row by the width. =SUM(B2:G2)/COLUMNS(B2:G2) divides by the number of columns, including empty ones. AVERAGE ignores empty cells, so the two answers differ when cells are blank.
  • A column number for lookups that fill across. =VLOOKUP($A9, $A$1:$E$6, COLUMNS($B1:B1), FALSE) gives 1 in the first cell, 2 in the next, and so on, because the end of the range moves as you copy it. Unlike COLUMN, it still works if columns are inserted to the left of the table. Add 1 if your table's first column is the lookup column.
  • Checking sizes. =COLUMNS(return_range)=COLUMNS(lookup_range) is a quick test that two ranges that are meant to line up do.

COLUMNS compared with related functions

  • COLUMN returns the column number of a cell, a position on the sheet. COLUMNS returns a count.
  • ROWS is the equivalent for height.
  • COUNTA counts cells that aren't empty. COLUMNS counts all of them.

Whole rows

=COLUMNS(1:1) returns 16,384, the number of columns on a worksheet, not the number of columns with data. To count entries across a row, use COUNTA on the cells in that row.

Errors

COLUMNS returns #VALUE! if its argument isn't a reference or an array, such as plain text typed into the formula. If the argument is itself an error, such as a formula that returned #N/A, COLUMNS returns that error.

Arguments

array
The range, array or array formula to measure, such as B2:G2 or TEXTSPLIT(A2, ","). COLUMNS counts the columns in its shape, not the cells that hold data.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Count the columns in a range

A4 =COLUMNS(B1:E1)

Result: 4

B to E is four columns. COLUMNS measures the shape of the range, so empty cells in it would still be counted.

A4
A
B
C
D
E
F
G
H
1
Region
Q1
Q2
Q3
Q4
2
3
Columns in B1:E1
4
4

A4 =COLUMNS(B1:E1) returns 4

Example 2

Count the items in a comma-separated list

B2 =COLUMNS(TEXTSPLIT(A2,","))

Result: 3

TEXTSPLIT cuts the text at each comma and spreads the pieces across columns. COLUMNS counts them. This needs Microsoft 365 or Excel 2021 or later.

B2
A
B
C
D
1
Tags
Number of tags
2
urgent,billing,refund
3
3
4

B2 =COLUMNS(TEXTSPLIT(A2,",")) returns 3

Example 3

Average across a row, counting empty cells

H2 =SUM(B2:G2)/COLUMNS(B2:G2)

Result: 34.1666666666667

The total is 205 and the range is six columns wide, so the result is 34.17. AVERAGE would give 51.25, because it ignores May and June, which are still empty.

H2
A
B
C
D
E
F
G
H
1
Region
Jan
Feb
Mar
Apr
May
Jun
H1 average
2
North
48
52
50
55
34.16666667
3
4

H2 =SUM(B2:G2)/COLUMNS(B2:G2) returns 34.1666666666667

Example 4

A lookup column number that survives inserted columns

B7 =VLOOKUP($A7,$A$1:$E$4,COLUMNS($A1:B1),FALSE)

Result: 31750

COLUMNS($A1:B1) counts two columns, so VLOOKUP returns the second column of the table. Copied right, the range grows to $A1:C1 and the count becomes 3, and so on.

B7
A
B
C
D
E
1
Region
Q1
Q2
Q3
Q4
2
North
48,200
51,400
49,800
57,900
3
South
31,750
33,100
35,200
36,800
4
East
42,900
41,300
44,600
47,100
5
6
Region
Q1
Q2
Q3
Q4
7
South
31,750
8
9
10

B7 =VLOOKUP($A7,$A$1:$E$4,COLUMNS($A1:B1),FALSE) returns 31750

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B4, return the number of month columns in B1:G1, using a function that measures the size of the range.

Answer in B4.

B4
A
B
C
D
E
F
G
H
1
Region
Jan
Feb
Mar
Apr
May
Jun
2
North
48
52
50
3
4
Months in the table
5
6
Tags
Number of tags
7
late,damaged,refund,urgent
8

Common mistakes

  • COLUMNS counts the shape of the range, not the entries in it. COLUMNS(B2:Z2) is 25 even if only 3 cells hold data. Use COUNTA to count entries.
  • COLUMNS(1:1) is 16,384, the full width of the worksheet. It is almost never what you want.
  • A range that includes a label column counts it. COLUMNS(A1:F1) is 6, even though there are only 5 data columns.
  • COLUMNS needs a reference or an array. A typed-in text argument returns #VALUE!.
  • COLUMNS(TEXTSPLIT(...)) counts the pieces, including empty ones when delimiters sit next to each other, because TEXTSPLIT keeps them as empty pieces by default.

Questions people ask

What is the difference between COLUMNS and COUNTA?

COLUMNS counts every column in a range, filled or not. COUNTA counts only the cells that aren't empty. For `B2:G2` with four entries, COLUMNS returns 6 and COUNTA returns 4.

What is the difference between COLUMN and COLUMNS?

COLUMN returns the column number of a cell: `COLUMN(D1)` is 4. COLUMNS returns how many columns a range has: `COLUMNS(A1:D1)` is 4.

How do I count the items in a comma-separated list?

In Microsoft 365 or Excel 2021 or later, `=COLUMNS(TEXTSPLIT(A2, ","))`. In older versions, count the commas and add one: `=LEN(A2)-LEN(SUBSTITUTE(A2,",",""))+1`.

Does COLUMNS include hidden columns?

Yes. COLUMNS counts the columns in the shape of the range, hidden or not.

Learn COLUMNS in a real sheet.

Tracks take you from the basics to modelling, one graded exercise at a time.