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 =COLUMNS(B1:E1) returns 4
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()
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 =COLUMNS(B1:E1) returns 4
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.
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.
=COLUMNS(TEXTSPLIT(A2, ",")) counts how many comma-separated items a cell holds. For red,green,blue it returns 3.=COLUMNS(UNIQUE(A2:H2, TRUE)) counts distinct values across a row.=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.=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.=COLUMNS(return_range)=COLUMNS(lookup_range) is a quick test that two ranges that are meant to line up do.=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.
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.
B2:G2 or TEXTSPLIT(A2, ","). COLUMNS counts the columns in its shape, not the cells that hold data.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
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 =COLUMNS(B1:E1) returns 4
Example 2
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 =COLUMNS(TEXTSPLIT(A2,",")) returns 3
Example 3
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 =SUM(B2:G2)/COLUMNS(B2:G2) returns 34.1666666666667
Example 4
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 =VLOOKUP($A7,$A$1:$E$4,COLUMNS($A1:B1),FALSE) returns 31750
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.
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.COLUMNS(A1:F1) is 6, even though there are only 5 data columns.#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.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.
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.
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`.
Yes. COLUMNS counts the columns in the shape of the range, hidden or not.
Tracks take you from the basics to modelling, one graded exercise at a time.