+ Reply to Thread
Results 1 to 6 of 6

Summing up a variable range of cells

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2011
    Location
    UK
    MS-Off Ver
    Excel 365
    Posts
    57

    Summing up a variable range of cells

    I am sure this is not difficult, I ma just struggling with the syntax.

    On a worksheet I want to be able to specify two rows as row numbers. rowA and rowB.

    Then elsewhere I want to be able to write a formula that sums up the cells in a fixed column on a different sheet between those two rows.

    Something like this....

    SUM(CELL('Sheet1'ArowA, 'Sheet1'ArowB)

    Which is summing up the cells between Row A Column A on Sheet 1 and Row B Column A on Sheet 1.

    I think the use of the Cell function to specify the cells would do, but I am struggling with the syntax to include a fixed column in the cell reference and a varaiable (other cell) for the row.

    I hope my requirement makes sense, as this would save me a lot of tedious work.


    Thanks in anticipation.

    (I will keep hacking away, and if I crack it will post the answer here)

  2. #2
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Summing up a variable range of cells

    Hello,

    You can do it with SUM function, for example you wanted to sum every cell within row 2 and row 9, from column A to column B, it will be like this
    =SUM(A2:B9)
    Column first, and row number second. You can change the cell Reference it to fit your data range.
    (copy pasta from Ford)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools

    Regards,
    Lem

  3. #3
    Registered User
    Join Date
    12-05-2011
    Location
    UK
    MS-Off Ver
    Excel 365
    Posts
    57

    Re: Summing up a variable range of cells

    Thanks for the reply, but that's not quite what I want. Maybe I wasn't clear.

    To take your example..

    I want to specify the 2 in A2 in one cell, and the 9 in B9 in a different cell

    The idea being that by changing the value in two cells I can change the scope of the range. The reason why this is important is because I will do this sum for different columns in many places and I want to change the row range easily without editing multiple cells.

  4. #4
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Summing up a variable range of cells

    I see, then you can use this set of formulas:
    Assuming you have the value of starting range (in your example, 2) in D1, use this formula in E1
    =ADDRESS(SMALL(IF($A$1:$B$12=$D1,ROW($A$1:$B$12)),1),SMALL(IF($A$1:$B$12=D1,COLUMN($A$1:$B$12)),1))
    This will return the Cell reference containing that value (closest to the left and up - having smallest row and column number as possible)
    And you have the ending range (in your example, 9) in D2, use this formula in E2
    =ADDRESS(LARGE(IF($A$1:$B$12=$D2,ROW($A$1:$B$12)),1),LARGE(IF($A$1:$B$12=D2,COLUMN($A$1:$B$12)),1))
    This will return the Cell Reference containing that value (furthest to the right and down - having largest row and column number as possible)
    And this one to calculate the sum of that range using E1 and E2
    =SUM(INDIRECT(E1&":"&E2))
    Here is a sample file.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-05-2011
    Location
    UK
    MS-Off Ver
    Excel 365
    Posts
    57

    Re: Summing up a variable range of cells

    Thanks Lem, I have just found my own solution (a lot of trial and error). This is my solution

    =SUM(INDIRECT("Totals!S"&H2):INDIRECT("Totals!S"&H3))

    If H2 = 10 and H3 = 20 then this is equivalent to

    SUM('Totals'!S10:'Totals'!S20)

    Thanks again

  6. #6
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Summing up a variable range of cells

    I see, so you only have to look it up in a column, I went ahead of myself and thought you might have more than 1 columns ...

    Still, I'm glad that you have found a solution best fit to your problem.

    Have a great day.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1