This guide covers everything you need to know about the Google Sheets COLUMNS function, including its definition, syntax, use cases, and how to use it.

Quick Jump

Toggle## What is the COLUMNS Function? How Does It Work?

The COLUMNS function in Google Sheets returns the total number of columns in a specified array or range. For example, if you’re working with a spreadsheet containing hundreds or even thousands of columns, manually counting them would be daunting. The COLUMNS function automates this process, enabling you to determine the column count quickly and accurately.

The COLUMNS function is often used in conjunction with other functions to create more complex formulas. For instance, it can be used with the ARRAYFORMULA or INDEX function to resize arrays or return specific cell values based on the column count.

## COLUMNS Syntax

The syntax and arguments for the function are as follows:

**COLUMNS(range)**

**The ‘range’ argument** in the function specifies the range of cells for which you want to return the column count.

Here are some important notes related to the syntax and argument of the COLUMNS function:

- It’s important to note that the ‘range’ argument can be a single cell, in which case the COLUMNS function will return 1 because a single cell is considered as a 1×1 range.
- If the range argument is omitted, the COLUMNS function will return the number of columns in the array or range of the cell where the function is entered.
- The COLUMNS function only counts actual columns, not the data within them. So, if a range has empty cells, they are still counted.
- The COLUMNS function is not case-sensitive. So, ‘A1:B2’ and ‘a1:b2’ are treated the same.
- You can’t use non-contiguous ranges as the argument for the COLUMNS function. For example, ‘A1:B2, D1:E2’ is not valid because the ranges are not connected.
- The COLUMNS function in Google Sheets does not count hidden columns. So, if columns are hidden in your specified range, they will not be included in the count.
- The function will return a #VALUE! error if the specified range is invalid. For example, if you specify ‘B1:A1’ as a range, the function will return an error because ‘B1’ is to the right of ‘A1’.

## Examples of How to Use the COLUMNS Function

Here are some practical examples of how to use the COLUMNS function in Google Sheets:

### Example #1: Counting the Number of Columns in a Range

Let’s say you have data in a range from A1 to E1 and want to count the number of columns in this range. You would use the COLUMNS function as follows:

**=COLUMNS(A1:E1)**

This formula will return the number 5, as there are five columns in the specified range (A, B, C, D, and E).

### Example #2: Using the COLUMNS Function in Lookup Formulas

The COLUMNS function can be used in combination with other functions to create more complex formulas. For example, you can use it with the INDEX and MATCH functions to create a horizontal lookup formula. If you have a dataset in a range from A1 to E5 and you want to find a specific value in the second row, you would use the COLUMNS function as follows:

**=INDEX(A2:E2, MATCH(F1, A1:E1, 0), COLUMNS(A1:E1))**

This formula will return the value in the second row that matches the value in F1, using the number of columns in the range A1:E1 as the column index.

### Example #3: Using the COLUMNS Function to Return an Array of Column Numbers

The COLUMNS function can be used to return an array of column numbers. For example, if you have a range from A1 to E1 and you want to return an array of column numbers, you would use the COLUMNS function as follows:

**=COLUMN(A1:E1)**

This formula will return an array of column numbers (1, 2, 3, 4, 5) for the specified range.

## Why Is COLUMNS Not Working? Troubleshooting Common Errors

If you’re experiencing difficulties with the COLUMNS function in Google Sheets, it’s not uncommon. Here are some common errors, their causes, and how you can fix them.

### #REF! Error

**Cause**: The #REF! error typically comes up when you reference a cell that doesn’t exist. This may occur when you incorrectly specify the range in your COLUMNS function.

**Solution**: To resolve this issue, double-check your formula to ensure your reference an actual range in your Google Sheets.

### #VALUE! Error

**Cause**: The #VALUE! error usually appears when the function’s input or arguments are of the incorrect data type. In the case of COLUMNS, you might see this error if you’re not inputting a range.

**Solution**: Make sure that you’re inputting a range of cells into your COLUMNS function. The correct syntax should be COLUMNS(A1:C3), wherein A1:C3 is your specified range.

### #NAME? Error

**Cause**: The #NAME? error is typically seen when Google Sheets doesn’t recognize text in the formula. If you’re seeing this error with the COLUMNS function, it’s likely because you’ve misspelled the function’s name.

**Solution**: Double-check your formula to ensure you’ve spelled “COLUMNS” correctly.

### #DIV/0! Error

**Cause**: The #DIV/0! error occurs when a formula tries to divide by zero. However, the COLUMNS function shouldn’t cause this error since it doesn’t involve any division operations.

**Solution**: If you’re seeing this error, it’s likely that there’s another part of your formula causing it. Check any other parts of your formula that involve division to ensure you’re not dividing by zero.

## Using COLUMNS With Other Google Sheets Functions

Combining the COLUMNS function with other Google Sheets functions can help you perform more complex tasks and calculations. The COLUMNS function can be used with several other functions like INDEX, MATCH, ARRAYFORMULA, and more. Let’s explore how to use COLUMNS with these functions.

### With INDEX

**Usage**: You can use the COLUMNS function with the INDEX function to return a value from a specific cell within a range. The COLUMNS function can be used to provide the column number argument to the INDEX function.

**Example**: Suppose you have a data set in range A1:F6 and want to return the value in the last column of the 3rd row. You can use the COLUMNS function to count the number of columns in the range and provide this as the column number to the INDEX function.

Here’s how you can do it:

**=INDEX(A1:F6, 3, COLUMNS(A1:F6))**

This formula will return the value in cell F3.

### With MATCH

**Usage**: The COLUMNS function can be used with the MATCH function to return the relative position of a specific item in a range.

**Example**: Suppose you have a list of names in range A1:A10 and want to find the position of the name “John” in the list. You can use the COLUMNS function to provide the lookup array to the MATCH function.

Here’s how you can do it:

**=MATCH(“John”, A1:INDEX(A1:A10, COLUMNS(A1:A10), 1), 0)**

This formula will return the position of “John” in the range A1:A10.

### With ARRAYFORMULA

**Usage**: The COLUMNS function can be used with the ARRAYFORMULA function to create an array result that expands automatically based on the number of columns in a range.

**Example**: Suppose you have data in A1:C10 and want to create an array that contains the sum of each row. You can use the COLUMNS function to provide the number of columns to the ARRAYFORMULA function.

Here’s how you can do it:

**=ARRAYFORMULA(SUM(A1:INDEX(A1:C10, ROW(A1:C10), COLUMNS(A1:C10))))**

This formula will return an array that contains the sum of each row in the range A1:C10.

For more details on the COLUMNS function, check out the official documentation at the Google Docs Editors Help Center.