+ Reply to Thread
Results 1 to 12 of 12

Sum a variable number of cells

Hybrid View

  1. #1
    Registered User
    Join Date
    05-01-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    6

    Sum a variable number of cells

    Essentially, I would like to have a cell in A2 sum up the values in cells A1, B1, C1 where the number of cells it sums is a variable in another cell that may change. I would like the same to apply to cell B2, C2, D2, etc.

    This may make more sense if you look at the attachment.

    Thanks! This puzzle has been bugging me for a while.
    Attached Files Attached Files

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sum a variable number of cells

    it might be a better idea to show what is, not what is not! giving the total you expect
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    05-01-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Sum a variable number of cells

    Huh? Sorry, I don't understand your reply.

  4. #4
    Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    270

    Re: Sum a variable number of cells

    Do you want the variable to be truly Variable or will it be within a range? IE 1-5 or do you want it to be whatever you enter?
    "I am not a rocket scientist, I am a nuclear engineer." - Split_atom18
    If my advice has been helpful to you, then please help me by clicking on the "Star" and adding to my reputation, Thanks!

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sum a variable number of cells

    Huh? Sorry, I don't understand your reply.
    and where 5 is a variable (in my example it is not)
    well show one where it is then!

    if you post a couple of examples with 5 or whatever /wherever its supposed to be
    then calculate the result manually an put it where you'd like the function to be, to give result.
    it might be clear to you but i lost my crystal ball
    Last edited by martindwilson; 05-01-2009 at 05:43 PM.

  6. #6
    Registered User
    Join Date
    05-01-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Sum a variable number of cells

    Ahh. I see your confusion Martin.

    I would like to sum X number of cells, where X is the variable, and in my example it is set at 5. Each cell in the second line sums 5 cells. In the second example it is set at 3, where each cell in the second line sums 3 cells. X will need to range from 1-10.

    Does this make it more clear?

    Thanks for following up.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    270

    Re: Sum a variable number of cells

    He is saying(I think)

    If Cell L2 is 5 Then

    Cell B2 would contain the following formula:

    =Sum(B2:F2)

    Cell C2 would contain the following formula:

    =Sum(C2:G2)

    etc etc

    If Cell L2 is 3 Then

    Cell B2 would contain the following formula:

    =Sum(B2:D2)

    Cell C2 would contain the following formula:

    =Sum(C2:E2)

    etc etc

    Hope this helps you martindwilson,

    Dan

  8. #8
    Registered User
    Join Date
    05-01-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Sum a variable number of cells

    split_atom18 is right in meaning - the actual formula needed can differ (i just realized a 'if' statement might work, but may get unwieldy)

  9. #9
    Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2010
    Posts
    280

    Re: Sum a variable number of cells

    For the example provided you could use the OFFSET function.

    =SUM(OFFSET(A1,0,0,1,$L2))
    Assumes Column L is fixed.

  10. #10
    Registered User
    Join Date
    05-01-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Sum a variable number of cells

    Awesome! Never realized offset had the width/height ability.

    Thanks.

  11. #11
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Sum a variable number of cells

    Quote Originally Posted by lhmome View Post
    Awesome! Never realized offset had the width/height ability.

    Thanks.
    True but it's also Volatile so avoid it if you can, normally when using OFFSET an INDEX approach is equally viable and non-Volatile, using your example:

    A2: =SUM(A1:INDEX(A1:$IV1,$L2))
    copy across ... apply to row 6 in the same manner

  12. #12
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sum a variable number of cells

    just worked that out myself as well, but make sure you have no cells containing numbers at least as far away from the last number in your summed range or it will be added on to the sum. so if L2=5 you are summing in range A1:K1, L1:O1 mustn't have numbers in.

+ 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