Syntax. COLUMN(reference)
Definition. This function returns the column number of a reference.
Arguments
reference (optional). Must evaluate to a cell reference or cell range
Background. If you omit the reference argument, the function returns the column number corresponding to the cell containing the function.
If the reference is a cell range (which can also be specified with a name), you can use the function in array formulas. If the destination range includes fewer columns than the argument, the information that would be in the missing cells is truncated. If the destination range is greater than range of the argument, the excess cells display the #N/A
error.
Example. Assume that you want to add up the numbers in a row with even (or odd) column numbers.
You cannot use the ISEVEN() or ISODD() functions, because these functions don’t accept references to multiple cells (they will give you a #VALUE!
error).
A number is even if the formula
(2*INT(A1/2)-A1)=0
returns the logical value TRUE
. In the case of
((2*INT(A1/2)-A1)<>0)=TRUE
the number is odd. If cells B21 through E21 contain numbers, the array formula
{=SUM((INT(COLUMN(B21:E21)/2)*2-COLUMN(B21:E21)=0)*B21:E21)}
returns the sum of all columns with even column numbers. The formula
{=SUM((INT(COLUMN(B21:E21)/2)*2-COLUMN(B21:E21)<>0)*B21:E21)}
returns all columns with odd column numbers. This works because TRUE is interpreted as 1 and FALSE as zero.