Tuesday, May 3, 2011

Excel sum with relative positions

How do I sum from whats in B2 to C2 ?

B2 = A10 or just 10 (preferred)
C2 = A25 or just 25 (preferred)

Normally you would just use SUM(A10:A25), but the values in B2 and C2 are not fixed, they change based on input. I can use MATCH to find the numbers, but how do I tell SUM to use those numbers ? The values to sum are always in the same column.

From stackoverflow
  • Use the INDIRECT() function. You pass it a string that is a range, which allows you to have a dynamic range based on input.

    Eoin Campbell : bah... beaten by seconds ;-)
  • You want to specify Cell Co-ordinates in the value of a Cell ?

    Is that what you're getting at ?

    Try Setting

    B1 = "A10"
    C1 = "A25"
    D1 = =SUM(INDIRECT(B1):INDIRECT(C1))
    
  • You can use the INDIRECT function for this, e.g.

    =SUM(INDIRECT(B2):INDIRECT(C2))

    if you can live with entering the entire cell name (A10, A25).

    Or to just have the numbers in B2 and C2, you could use

    =SUM(INDIRECT(ADDRESS(B2;1)):INDIRECT(ADDRESS(C2;1)))

    (Hope I got the columns and rows in the right order!)

0 comments:

Post a Comment