+ Reply to Thread
Results 1 to 8 of 8

How to sum a range to a cell based on another cells value

Hybrid View

Dulock How to sum a range to a cell... 08-15-2012, 02:31 AM
FDibbins Re: How to sum a range to a... 08-15-2012, 02:48 AM
Dulock Re: How to sum a range to a... 08-15-2012, 03:41 AM
CheshireCat Re: How to sum a range to a... 08-15-2012, 03:46 AM
Dulock Re: How to sum a range to a... 08-15-2012, 04:00 AM
Cutter Re: How to sum a range to a... 08-15-2012, 08:38 AM
Dulock Re: How to sum a range to a... 08-15-2012, 10:17 AM
Cutter Re: How to sum a range to a... 08-15-2012, 11:10 AM
  1. #1
    Registered User
    Join Date
    08-15-2012
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    4

    How to sum a range to a cell based on another cells value

    I have two worksheets, "values" and "keys"

    each value has a corresponding key, if the value of the first key is 7, I need to sum keys b2:b8 (value + 1 because of header)

    In other words, in case it wasn't clear already, is there a way I can reference (and increment) the value contained within "Values!B2" (Same sheet, I know I don't need to specify the sheet here, but writing it this way so all understand) in order to grab =sum(Keys!B2:B?) where ? = previously grabbed value + 1

    Thank you kindly for any help!

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: How to sum a range to a cell based on another cells value

    the ? can be entered using the indirect() function. but perhaps you could also do the same thing using sumif() or sumifS()?
    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
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    08-15-2012
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to sum a range to a cell based on another cells value

    Argh, I can't even use the reply feature properly tonight. It's no wonder Excel is beyond me...

    Anyway, as I was saying before I deleted my reply...Thanks FDibbins, this certainly looks promising, and I can see how I can use this elsewhere, but I can't seem to make it work for me in this case...

    Results:
    =sum(keys!INDIRECT("B"&$B$24:"B"&$B$2))
    gives me error: parse error (I never thought this was right, tried it last)
    =sum(keys!B2:INDIRECT("B"&$B$2))
    gives me error: unknown range name keys!B2
    =sum(INDIRECT("keys!B"&$B$24:"keys!B"&$B$2))
    gives me error: unknown sheet name <--also slightly ugly since I have to meaninglessly store a value of "2" somewhere in my sheet to reference...

    ---------- Post added at 11:41 PM ---------- Previous post was at 11:34 PM ----------

    Argh, I was misreading something....and was concatenating entirely wrong.

    =sum(INDIRECT("keys!B"&$B24&":keys!B"&$B2))
    This works. I bet I can get the second one to work as well with this...
    Last edited by Dulock; 08-15-2012 at 03:36 AM. Reason: Trying some better formatting...

  4. #4
    Forum Contributor CheshireCat's Avatar
    Join Date
    10-11-2011
    Location
    Victoria, Canada
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    258

    Re: How to sum a range to a cell based on another cells value

    Kinda ugly, but try this:

    =SUM(INDIRECT(ADDRESS(2,2,1,1,"Keys")&":"&ADDRESS(B2,2,1,1)))
    Replace any of the numerical values in the formula to control the range (e.g. B2 in second ADDRESS).
    Docendo discimus.

  5. #5
    Registered User
    Join Date
    08-15-2012
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to sum a range to a cell based on another cells value

    *chuckles* okay, I admit, I don't understand how your thing works CheshireCat, but it does. I think I'm going to go to bed with a smile on my face now, and come back and study what in the world is going on in there after I've had some rest.

    Thanks to both of you!

  6. #6
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How to sum a range to a cell based on another cells value

    Hello Dulock , and welcome to the forum.

    Try this:

    =SUM(Keys!B2:INDEX(Keys!B:B,Values!B2+1))

  7. #7
    Registered User
    Join Date
    08-15-2012
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to sum a range to a cell based on another cells value

    Quote Originally Posted by Cutter View Post
    =SUM(keys!B2:INDEX(keys!B:B,Values!B2+1))
    Hi Cutter! Thanks for the help/suggestion, however (sadly) I get the same error with that one as I do with this one:
    =sum(keys!B2:INDIRECT("B"&$B$2))
    error: unknown range name keys!B2

    It seems as if using a function call on the second half of the range confuses it. And I just cannot seem to figure out how to encapsulate it properly (single or double quotes, parentheses, etc...).

  8. #8
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How to sum a range to a cell based on another cells value

    Odd, what I gave you is copied straight from a test file and it's working for me.

    Maybe because you have a range named the same as the sheet? Excel can be come confused at times.

    Here's the test file:
    Attached Files Attached Files

+ 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