Search code examples
excelrangeformulanamed

How to use a named column in Excel formulas


I know how to make a named range in Excel.

I have a spreadsheet, with various columns going across as parameters, and then finally a formula in the last cell. This is repeated many times in each row, with each row having a different set of data, and the formula updated to reference the correct row index.

However, the formula looks like (three rows worth):

=G2*(10*D2 + 20*E2 + 5*F2)
=G3*(10*D3 + 20*E3 + 5*F3)
=G4*(10*D4 + 20*E4 + 5*F4)

I would like to use named ranges, but I can't find a way to do something like

=Count * (10*var1 + 20*var2 + 5*var3)

where count, var1, var2, and var3 automatically update to be the particular column of the current row. I can create a named range for every cell, but that isn't helpful. I can name range the column, but then I can't find a way to put an offset into the formula.

Also the whole point of this is readability, so if it ends up being some nasty complex formula function call, that probably doesn't help too much.


Solution

  • Suppose I have the following numbers set up in columns D to F in rows 2 to 4:

        D    E    F    G
    2   10   15   20
    3   1    2    3
    4   20   30   40
    

    Now suppose I want the value in column D to be known as input1, column E to be input2, and column F to input3:

    In Insert > Name > Define...

    input1 RefersTo =OFFSET(Sheet1!$D$2,0,0,COUNT(Sheet1!$D:$D),1)
    input2 RefersTo =OFFSET(Sheet1!$E$2,0,0,COUNT(Sheet1!$E:$E),1)
    input3 RefersTo =OFFSET(Sheet1!$F$2,0,0,COUNT(Sheet1!$F:$F),1)
    

    Now if I write my formula in column G as follows I should get correct answers:

    G2 =(10*input1+20*input2+30*input3) // 1000
    G3 =(10*input1+20*input2+30*input3) // 140
    G5 =(10*input1+20*input2+30*input3) // 2000