# How to use the COLUMN function

The COLUMN function returns the column number of the top-left cell of a cell reference. If the argument is not entered the column number of the cell the formula is entered in is returned, see cell B6 in the picture above.

#### Table of Contents

- COLUMN Function Syntax
- COLUMN Function Arguments
- COLUMN Function Example
- How to convert a column number to a column letter?
- How to convert a column letter to a column number?
- How can the Column function return an array?
- Column function and VLOOKUP
- Column function of other functions
- Column function with a cell ref to a cell range?
- Create a horizontal sequence
- Column function and SMALL function
- How to use the Column function in VBA
- Get Excel file
- Extract table headers based on a condition

## 1. COLUMN Function Syntax

COLUMN(*reference*)

## 2. COLUMN Function Arguments

reference |
Optional. The cell reference for which you want to extract the column number from. |

The COLUMN function allows you to also return an array of column numbers if you enter the formula as an array formula and use a cell range containing multiple columns.

You can not use multiple cell references in the COLUMN function.

## 3. COLUMN Function example

Formula in cell B3:

Column letter V corresponds to column number 22. A is 1, B is 2, and so on.

## 4. How to convert a column number to a column letter?

The formula in cell C3 calculates the column letter from a column number. Column number 1 is column A, column 2 is B, and so on. See the image above.

Formula in cell C3:

### 4.1 Explaining formula in cell C3

#### Step 1 - Calculate cell address

TheÂ ADDRESS function returns the address of a specific cell, you need to provide a row and column number.

ADDRESS(*row_num*,Â *column_num*, [*abs_num*], [*a1*], [*sheet_text*])

ADDRESS(1,B3,4,1)

becomes

ADDRESS(1,22,4,1)

and returns "V1".

#### Step 2 - Calculate number of characters in cell address

The LEN function calculates the number of characters in a given string.

LEN(ADDRESS(1,B3,4,1))-1

becomes

LEN("V1")-1

becomes

2-1 equals 1.

#### Step 3 - Extract column letter from cell address

TheÂ LEFT functionÂ extracts a specific number of characters always starting from the left.

LEFT(ADDRESS(1,B3,4,1), LEN(ADDRESS(1,B3,4,1))-1)

becomes

LEFT("V1", 1)

and returns "V" in cell C3.

## 5. How to convert a column letter to a column number?

The formula in cell C3 calculates the column number from a column letter. Column number 1 is column A, column 2 is B, and so on. See the image above.

Formula in cell C3:

### 5.1 Explaining formula in cell C3

#### Step 1 - Concatenate strings

The ampersand character lets you concatenate values.

B3&1

becomes

"V"&1

and returns "V1".

#### Step 2 - Create cell reference

The INDIRECT function returns the cell reference based on a text string.

INDIRECT(B3&1)

becomes

INDIRECT("V1")

and returns cell reference V1.

#### Step 3 - Calculate column number

COLUMN(INDIRECT(B3&1))

becomes

COLUMN(V1)

and returns 22 in cell C3.

## 6. How can the COLUMN function return an array?

The COLUMN function calculates the column number from a cell reference, the column function returns an array of numbers if the cell reference points to a cell range that has multiple columns.

Formula in cell B3:

The formula in cell B3 returns a horizontal array of numbers from 1 to 3 representing the column numbers of cells A1, B1, and C1. Column letter A is 1, column 2 is B, and so on.

You need to enter this formula in cell B3 as an array formula if you own an earlier Excel version than Excel 365.

## 7. COLUMN function and VLOOKUP

The formula in cell C3 combines the VLOOKUP and the COLUMN functions to get all values from the same row if the lookup value matches the leftmost value in the table array.

Formula in cell B3:

### 7.1 Explaining formula in cell C10

#### Step 1 - Calculate column number

The cell reference (B1) changes when you copy the cell and paste it to adjacent cells. This makes the COLUMN function return a different value in each cell.

COLUMN(B1) returns 2.

#### Step 2 - Evaluate VLOOKUP function

The VLOOKUP function lets you search the leftmost column for a value and return another value on the same row in a column you specify.

VLOOKUP(*lookup_value*, *table_array*, *col_index_num*, [*range_lookup*])

The third argument lets you choose which column to fetch a value from, this allows us to get all values from the same row when we copy the cell and paste it to adjacent cells.

VLOOKUP($B10,$B$3:$F$7,COLUMN(B1))

becomes

VLOOKUP($B10,$B$3:$F$7, 2)

and returns "ASD" in cell C10.

## 8. COLUMN function of other columns

The COLUMN function accepts no arguments at all, this will return the column number of the cell that the function is entered in.

Formula in cell B3:

The formula above does not change when you copy the cell and paste it to adjacent cells, however, the output is different. Cell C3 is the third column and therefore 3 is returned.

You can also use a cell reference to any other column or columns, see the formula below.

Formula in cell B6:

This formula returns the column number of cell K1 which is the argument used in this example. The cell reference is a relative cell reference meaning it changes when you copy the cell and pastes it to adjacent cells, see cell range C6:D6 in the image above.

The formula below returns an array of numbers 11, 12, and 13. They correspond to the cells in cell range K1:M1 and represent their column numbers.

Formula:

You need to enter this formula as an array formula in order to see all numbers in the array unless you are using Excel 365. Note that the array is a horizontal array with the same size as there are cells in the supplied cell range.

## 9. COLUMN function with a cell ref to a cell range?

The COLUMN function repeats the array of numbers if entered in a cell range.

Array formula in cell B3:

Note, the formula is entered as a regular formula if your Excel version is 365.

## 10. Create a horizontal sequence

The COLUMN function can create a sequence of numbers that can be useful both in formulas and on a worksheet.

Formula in cell B3:

The formula above creates a horizontal sequence from 1 to n or as far as you copy the formula.

Formula in cell B6:

The formula in cell B6 creates a horizontal sequence containing odd numbers from 1 to n. Copy cell B6 and paste to adjacent cells on the same row as far as needed.

Formula in cell B9:

The formula in cell B9 creates a horizontal sequence containing odd numbers from 1 to n.

Note, relative cell references and the COLUMN function are sensitive to inserting rows and columns. The formula will break if you insert a column or row before the formula.

Use the COLUMNS function with a cell reference containing both an absolute and relative cell reference to solve this problem.

=COLUMNS($A$1:A1)

## 11. COLUMN function and SMALL function

The COLUMN function combined with the SMALL function can extract and sort numbers from a cell range or array.

Formula in cell B8:

This is a regular formula.

### 11.1 Explaining formula in cell B8

#### Step 1 - Calculate sequence number

COLUMN(A1) returns 1.

#### Step 2 - Evaluate SMALL function

The SMALL function returns the k-th smallest value from a group of numbers. The first argument is a cell range or array that you want to find the k-th smallest number from.

The second and last argument is k which is a number from 1 up to the number of values you have in the first argument.

SMALL(*array*,Â *k*)

SMALL($B$3:$B$5, COLUMN(A1))

becomes

SMALL($B$3:$B$5, 1)

becomes

SMALL({5; -2; 3}, {1})

and returns -2.

## 12. How to use the COLUMN function in VBA?

The COLUMN function does not exist in the WorksheetFunction object. You can use the RANGE.COLUMN property to achieve the same thing.

The macro below saves the column number from cell B3 to cell B3. Column B is the second column.

Sub Macro1() Range("B3") = Range("B3").Column End Sub

## 14. Extract table headers based on a condition

This article demonstrates an array formula that returns the table header based on a condition. For example, in cell C8 the formula returns A because 1 is found in cell C2 and C4.

The formula in cell C9 returns A because 2 is found once in cell range C3:C5, the condition is in column B.

**Vikas asks:**

i need to extract the headers from a grid based on value in left most column

example

row header ---> a b c d e

data 1 1 2 2 2

2 1 1

1 1 1 2

so how to find out which all headers appear agst 1 or 2o 3 in each row

The following array formula extracts column headers based on the condition in cell B8 and cells below.

Array formula in cell C8:

Excel 365 dynamic array formula in cell C8:

Copy cell C8 and paste to cells below as far as needed.

### How to create an array formula

- Copy array formula
- Select cell B7
- Paste formula in formula bar
- Press and hold Ctrl + Shift
- Press Enter

### How to copy array formula

- Select cell B7
- Copy cell (not formula)
- Select cell range C7:F7
- Paste (Ctrl +v)

### Explaining array formula in cell C8

**Step 1 - Filter column numbers**

The IF function checks if value in cell B8 is equal to any of the cells in cell range C3:G5.

IF($B8=$C$3:$G$5, COLUMN($C$3:$G$5), "")

IF(*logical_test*,* [value_if_true]*, *[value_if_false]*)

The logical_test is $B8=$C$3:$G$5, it returns TRUE if equal and FALSE if not equal.

IF($B8=$C$3:$G$5, COLUMN($C$3:$G$5), "")

becomes

IF("1"={1, 1, 2, 2, 2;2, 1, 1, 0, 0;1, 1, 1, 2, 0}, {1, 2, 3, 4, 5}, "")

becomes

IF({TRUE, TRUE, FALSE, FALSE, FALSE;FALSE, TRUE, TRUE, FALSE, FALSE;TRUE, TRUE, TRUE, FALSE, FALSE}, {1, 2, 3, 4, 5}, "")

and returns

{1, 2, "", "", "";"", 2, 3, "", "";1, 2, 3, "", ""}

This array tells us that 1 is found in column 1, 2 and 3.

**Step 2 - Calculate the frequencies of the numbers in the array**

The FREQUENCY function allows you to extract only one instance of each header.

FREQUENCY(IF($B8=$C$3:$G$5, COLUMN($C$3:$G$5), ""), COLUMN($C$3:$G$5))

becomes

FREQUENCY({1, 2, "", "", "";"", 2, 3, "", "";1, 2, 3, "", ""}, {1, 2, 3, 4, 5})

and returns

{2;3;2;0;0;0}

If a value in this array is larger than 0 (zero) you know that the corresponding header is found in the cell range.

**Step 3 -Â Extract unique distinct numbers**

The IF function returns the corresponding column number if a value is larger than 0 (zero).

IF(FREQUENCY(IF($B8=$C$3:$G$5, COLUMN($C$3:$G$5), ""), COLUMN($C$3:$G$5))>0, ROW($A$1:$A$5), "")

becomes

IF({2;3;2;0;0;0}>0, {1; 2; 3; 4; 5}, "")

and returns

{1; 2; 3; ""; ""}

**Step 4 - Return the k-th smallest value**

The SMALL function returns the k-th smallest value in the array. SMALL(*array, k*)

SMALL(IF(FREQUENCY(IF($B8=$C$3:$G$5, COLUMN($C$3:$G$5), ""), COLUMN($C$3:$G$5))>0, MATCH(ROW($C$2:$C$6), ROW($C$2:$C$6)), ""), COLUMN(A1))

becomes

SMALL({1; 2; 3; ""; ""}, 1)

and returns 1.

**Step 5 - Return the value of a cell at the intersection of a particular row and column**

The INDEX function returns a value based on a row and column number.

INDEX($A$1:$E$1, SMALL(IF(FREQUENCY(IF($B8=$C$3:$G$5, COLUMN($C$3:$G$5), ""), COLUMN($C$3:$G$5))>0, MATCH(ROW($C$2:$C$6), ROW($C$2:$C$6)), ""), COLUMN(A1)))

becomes

INDEX($A$1:$E$1, 1)

becomes

INDEX({"A", "B", "C", "D", "E"}, 1)

and returns A in cell B7.

**Step 6 - Return value_if_error if expression is an error and the value of the expression itself otherwise**

The IFERROR function returns a blank (nothing) if an errror is returned.

=IFERROR(INDEX($A$1:$E$1, SMALL(IF(FREQUENCY(IF($B8=$C$3:$G$5, COLUMN($C$3:$G$5), ""), COLUMN($C$3:$G$5))>0, MATCH(ROW($C$2:$C$6), ROW($C$2:$C$6)), ""), COLUMN(A1))), "")

becomes

=IFERROR("A", "")

and returns A in cell C8.

### 'COLUMN' function examples

This post explains how to lookup a value and return multiple values. No array formula required.

This blog article describes how to split strings in a cell with space as a delimiting character, like Text to […]

Josh asks: now if i only knew how to apply these dependent dropdown selections to a filter, i'd be set. […]

### Functions in 'Lookup and reference' category

The COLUMN function function is one of 24 functions in the 'Lookup and reference' category.

### Excel function categories

### Excel categories

### 5 Responses to “How to use the COLUMN function”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

Is it possible with2 criteria? with intersection table lookup?

Thans in advanced

Azumi

Azumi,

can you explain in greater detail`?

Something Like this (Intersection Tables:

A B C

AA 1 1 2

BB 2 1 2

How to retrieve column headers with this criteria:

1 and AA --> result should be A and B

or

1 and 2 and AA --> result should be A, B and C

Thanks

Hi Oscar, It helped me a great deal.

I was wondering if is it possible to count also how many times 1 exists in each header? please see the link for better understanding my query. Thanks!