The COLUMNS function returns the number of columns in a specified array or range.
This can be useful when you need to know how many columns a specific range contains, for example, for data analysis or creating dynamic formulas.
Syntax
COLUMNS(array)
Argument |
Description |
Permitted values |
|---|---|---|
array |
Range of cells or array of values for which the number of columns needs to be determined |
Range of cells or a named range |
Examples of use
Counting columns in a range
If you have data in the A1:C10 range, you can count the number of columns as follows:
=COLUMNS(A1:C10).
Result: 3.
Counting columns using a named range
If you have created a named range, for example, “MyRange”, you can use it in a function:
=COLUMNS(MyRange)
The result will depend on the size of the named range.
Counting columns in a single column
If you specify a range containing only one column, for example A1:A10:
=COLUMNS(A1:A10)
Result: 1.
Notes
–The COLUMNS function returns an integer representing the number of columns in the specified range.
–If the range is empty, the function returns 0.