+ Reply to Thread
Results 1 to 9 of 9

Sum a range based on information from two different columns

  1. #1
    Registered User
    Join Date
    09-11-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2002, 2003,2007
    Posts
    39

    Sum a range based on information from two different columns

    I have found a lot of posts that are close, but not quite what I'm looking for (I think).

    What I have is a from and to path in columns A and B, and a corresponding distance in C.

    I am giving the user the option to pick Points along the path and I want it to report the corresponding distance (i.e. from A to F should be around 5,200).

    Attached is the file. I think I need and index and a sumif or sumproduct, but I can't quite figure it out.

    Thanks in advance.

    J
    Attached Files Attached Files
    Last edited by new.vbacoder; 10-01-2010 at 04:58 PM.

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

    Re: Sum a range based on information from two different columns

    Pre XL2007 2 SUMIFs should work

    Please Login or Register  to view this content.
    (or use SUMPRODUCT but I'd opt for above myself)

    XL2007+ use SUMIFS.

    Please Login or Register  to view this content.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,247

    Re: Sum a range based on information from two different columns

    One way:

    Cell G2: =SUM(INDIRECT("C"& MATCH(E2,$A$2:$A$11,0)+1 & ":C" & MATCH(F2,$B$2:$B$11,0)+1))

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    09-11-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2002, 2003,2007
    Posts
    39

    Re: Sum a range based on information from two different columns

    Quote Originally Posted by TMShucks View Post
    One way:

    Cell G2: =SUM(INDIRECT("C"& MATCH(E2,$A$2:$A$11,0)+1 & ":C" & MATCH(F2,$B$2:$B$11,0)+1))

    Regards
    That works when the data is on the same sheet, but when the reference is in a different workbook (i.e. the data in column A-C is in A.xls and the data in columns E-G is in B.xls).

    What do I need to modify the "C" and ":C" to? I'm assuming that's the column reference for the distance?

    Thanks

    J

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,247

    Re: Sum a range based on information from two different columns

    That would be:

    Cell G2 in Book B, referring to Book A:

    Please Login or Register  to view this content.


    Regards

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

    Re: Sum a range based on information from two different columns

    FWIW, none of the suggestions made thus far will work should the target workbook be closed - should that be the case then use SUMPRODUCT (or Array) equiv. of the SUMIFS approach illustrated previously.

    Even if the target is always open when the calculation workbook is open I would be very wary of having Volatile links (ie INDIRECT).

  7. #7
    Registered User
    Join Date
    09-11-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2002, 2003,2007
    Posts
    39

    Re: Sum a range based on information from two different columns

    Quote Originally Posted by DonkeyOte View Post
    Pre XL2007 2 SUMIFs should work

    Please Login or Register  to view this content.
    My example was very generic (i.e. A to B, B to C, etc), and your code works great for that, but the real data has differing names, such as Winding Way or Burnside, and when using the above formula, the first row becomes negative and not even the correct value, and the second comes in positive, but not the correct value. I've also included the INDIRECT formula, as that seems to work either way. However, when trying to do INDIRECT over different spreadsheets, I can't get the formulas to work.

    Here's the code for my specific example

    Please Login or Register  to view this content.
    Where Column B is the same as Column A in test, and Column D is the same as Column C.

    I've re-attached test with the names included, as well as the basic letters.

    Any thoughts??

    J
    Attached Files Attached Files
    Last edited by new.vbacoder; 10-01-2010 at 03:22 PM.

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

    Re: Sum a range based on information from two different columns

    Perhaps try:

    Please Login or Register  to view this content.
    In the above it is assumed that in [Travel Time.xls] From is B, To is C and Distance is D.

  9. #9
    Registered User
    Join Date
    09-11-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2002, 2003,2007
    Posts
    39

    Re: Sum a range based on information from two different columns

    Message deleted by user.
    Last edited by new.vbacoder; 03-24-2011 at 02:34 PM.

+ 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