## Summary

To get a full set of relative column numbers in a range, you can use an array formula based on the COLUMN function.

In the example shown, the array formula in B4:H4 is:

``````{=COLUMN(B4:H4)-COLUMN(B4)+1}
``````

On the worksheet, this must be entered as multi-cell array formula using Control + Shift + Enter

This is a robust formula that will continue to generate relative numbers even when columns are inserted in front of the range.

## Generic formula

``{=COLUMN(range)-COLUMN(range.firstcell)+1}``

## Explanation

The first COLUMN function generates an array of 7 numbers like this:

``````{2,3,4,5,6,7,8}
``````

The second COLUMN function generates an array with just one item like this:

``````{2}
``````

which is then subtracted from the first array to yield:

``````{0,1,2,3,4,5,6}
``````

Finally, 1 is added to get:

``````{1,2,3,4,5,6,7}
``````

### With a named range

You can adapt this formula to use with a named range. For example, in the above example, if you created a named range "data" for B4:H4, you can use this formula to generate column numbers:

``````{=COLUMN(data)-COLUMN(INDEX(data,1,1))+1}
``````

You'll encounter this formula in other array formulas that need to process data column-by-column.

### With SEQUENCE

With the SEQUENCE function the formula to return relative row columns for a range is simple:

``````=SEQUENCE(COLUMNS(range))
``````

The COLUMNS function provides the count of columns, which is returned to the SEQUENCE function. SEQUENCE then builds an array of numbers, starting with the number 1.  So, following the original example above, the formula below returns the same result:

``````=SEQUENCE(COLUMNS(B4:H4)) // returns {1;2;3;4;5;6;7}
``````

Note: the SEQUENCE formula is a new dynamic array function available only in Excel 365. Author ### Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.