+ Reply to Thread
Results 1 to 18 of 18

Lookup value from range for corresponding row where multiple criteria are met

  1. #1
    Registered User
    Join Date
    02-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    9

    Lookup value from range for corresponding row where multiple criteria are met

    Hi forum members,

    Please can you advise on how to make the following look up functionality in Excel 2007 work:

    From a range in column A I want to display the value from the row that has the satisfied corresponding criteria in other columns.
    The following does work if each criteria array is in a single column:

    Please Login or Register  to view this content.
    The problem I have is that data setup has changed and now the 2nd criteria (Sheet2'!D2) can be present in any column of multi-column range (on Sheet1). However, adjusting my formula to that new range (by extending column reference) results in a #value error:

    Please Login or Register  to view this content.
    Obviously, I doing something wrong, or need a different approach, but can't figure out how.

    Hoping you can help me.

    Many thanks,

    Mark
    Last edited by 0Twintig; 09-03-2013 at 01:06 PM. Reason: Solution provided

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Lookup value from range for corresponding row where multiple criteria are met

    What did you change? Both formulae look same to me.

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Working fine for me..

    =INDEX(Sheet1!$A$1:$A$50,SUMPRODUCT((Sheet1!$AR$1:$AR$50="No")*(Sheet1!$BF$1:$BF$50=Sheet2!D2)*(Sheet1!$D$1:$D$50=Sheet2!F2),ROW(Sheet1!$A$1:$A$50)))


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Registered User
    Join Date
    02-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Hi zbor,

    What did you change? Both formulae look same to me.
    - copy and paste error (now corrected in my initial post).

    The formula that results in #value is:
    Please Login or Register  to view this content.

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Lookup value from range for corresponding row where multiple criteria are met

    try use * instead of -- (in case of multiple columns):

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Quote Originally Posted by :) Sixthsense :) View Post
    Working fine for me..

    =INDEX(Sheet1!$A$1:$A$50,SUMPRODUCT((Sheet1!$AR$1:$AR$50="No")*(Sheet1!$BF$1:$BF$50=Sheet2!D2)*(Sheet1!$D$1:$D$50=Sheet2!F2),ROW(Sheet1!$A$1:$A$50)))
    Yes, this is the formula using the criteria array in a single column.
    The issue is that the criteria array is now multi-column (i.e. 'Sheet1'!$CE$1:$CN$50=Sheet2'!D2 )

  7. #7
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Try this...

    =INDEX(Sheet1!$A$1:$A$50,SUMPRODUCT((Sheet1!$AR$1:$AR$50="No")*COUNTIF(Sheet1!$CE$1:$CN$50,Sheet2!D2)*(Sheet1!$D$1:$D$50=Sheet2!F2),ROW(Sheet1!$A$1:$A$50)))

  8. #8
    Registered User
    Join Date
    02-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Quote Originally Posted by zbor View Post
    try use * instead of -- (in case of multiple columns):

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Unfortunately, still results in #value error

  9. #9
    Registered User
    Join Date
    02-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Quote Originally Posted by :) Sixthsense :) View Post
    Try this...

    =INDEX(Sheet1!$A$1:$A$50,SUMPRODUCT((Sheet1!$AR$1:$AR$50="No")*COUNTIF(Sheet1!$CE$1:$CN$50,Sheet2!D2)*(Sheet1!$D$1:$D$50=Sheet2!F2),ROW(Sheet1!$A$1:$A$50)))
    In this case it is giving a #REF! error, which seems strange as all the cells references are correct

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Lookup value from range for corresponding row where multiple criteria are met

    #REF! will not only occur when the reference has got deleted. It will also occur when the mentioned range is not in the defined range reference

    For example
    =INDEX(A1:A4,5) will result #REF!
    Last edited by :) Sixthsense :); 09-03-2013 at 06:59 AM.

  11. #11
    Registered User
    Join Date
    02-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Quote Originally Posted by :) Sixthsense :) View Post
    #REF! will not only occur when the reference has got deleted. It will also occur when the mentioned range is not in the defined range reference

    For example
    =INDEX(A1:A4,5) will result #REF!
    As far as I'm aware the ranges are within defined range reference is. If you look at the attached example sheet - it emulates the problem.example sheet Lookup value from range for corresponding row where multiple criteria are met.xlsx

  12. #12
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Lookup value from range for corresponding row where multiple criteria are met

    The reason is that the countif is getting the result as 2 since there is two matches for 15 in D32 cell and E50 cell. The exact match is falling in 50th row.. so 2x50 = 100

    =SUMPRODUCT((Sheet1!$B$1:$B$50="No")*COUNTIF(Sheet1!$D$1:$M$50,Sheet2!D2)*(Sheet1!$C$1:$C$50=Sheet2!F2),ROW(Sheet1!$A$1:$A$50))

    But in Index there is only 50 rows..

    =INDEX(Sheet1!$A$1:$A$50

    So you are getting #REF! error

    So please ignore the method which I suggested to you since it makes no sense.

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Lookup value from range for corresponding row where multiple criteria are met

    This seems to work:

    =INDEX(Sheet1!A:A,SUMPRODUCT((Sheet1!$D$2:$M$60=Sheet2!D2)*(Sheet1!$B$2:$B$60="no")*(Sheet1!$C$2:$C$60=Sheet2!F2)*ROW(Sheet1!$B$2:$B$60)))
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  14. #14
    Registered User
    Join Date
    02-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Quote Originally Posted by JBeaucaire View Post
    This seems to work:

    =INDEX(Sheet1!A:A,SUMPRODUCT((Sheet1!$D$2:$M$60=Sheet2!D2)*(Sheet1!$B$2:$B$60="no")*(Sheet1!$C$2:$C$60=Sheet2!F2)*ROW(Sheet1!$B$2:$B$60)))
    Close....but no cigar! It does indeed work in the example file.
    However, my original data sheet is unfortunately setup with more data columns in between the data points referenced for this lookup - as per the column letters in the code of my initial post.
    Attached is the updated example file with the data in actual column positions.
    Your formula now results in #NA if applied using these range positions.
    Is there perhaps a way to adjust the formula so that it still works?

    As an FYI, cell Sheet2!F2 is actually the outcome of {=MAX(IF(COUNTIF(Sheet2'!D2,'Sheet1'!$CE$1:$CN$50),IF(Sheet1'$AR$1:$AR$50="No", 'Sheet1'!$D$1:$D$50))} which works well, so in my mind it should be possible to pull in the corresponding value from the row in column A in sheet1.

    example sheet Lookup value from range for corresponding row where multiple criteria are met - a.xlsx

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Lookup value from range for corresponding row where multiple criteria are met

    You had a typo in the new formula:

    =INDEX(Sheet1!A:A,SUMPRODUCT((Sheet1!$CE$2:$CN$60=Sheet2!D2)*(Sheet1!$AN$2:$AN$60="no")*(Sheet1!$D$2:$D$60=Sheet2!F2)*ROW(Sheet1!$AN$2:$AN$60)))

  16. #16
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Using SUMPRODUCT is OK if you can be sure you have only one row which matches the criteria - if you might have more than one row which satisfies the conditions (or no rows) then you might get odd results. Try this array formula to give you the column A value for the first instance

    =INDEX(Sheet1!$A$2:$A$60,SMALL(IF((Sheet1!$CE$2:$CN$60=Sheet2!D2)*(Sheet1!$AN$2:$AN$60="no")*(Sheet1!D2:D60=Sheet2!F2),ROW(Sheet1!$A$2:$A$60)-ROW(Sheet1!$A$2)+1),1))

    confirmed with CTRL+SHIFT+ENTER

    If there are no matches you get #NUM! error
    Last edited by daddylonglegs; 09-03-2013 at 11:35 AM.
    Audere est facere

  17. #17
    Registered User
    Join Date
    02-14-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Quote Originally Posted by JBeaucaire View Post
    You had a typo in the new formula:

    =INDEX(Sheet1!A:A,SUMPRODUCT((Sheet1!$CE$2:$CN$60=Sheet2!D2)*(Sheet1!$AN$2:$AN$60="no")*(Sheet1!$D$2:$D$60=Sheet2!F2)*ROW(Sheet1!$AN$2:$AN$60)))
    Thanks for spotting AND for the solution. Now it worked and it is like a very powerful aspirin - it instantly cured my headache!
    Although, I still had to apply a workaround because the data in Sheet1!$CE$2:$CN$60 isn't recognized as a number as it is the outcome of a split-single-cell-delimit-function (substitute and replace), while Sheet2!D2 is in a number format.
    Therefore, I created a new range to convert the content of columns CE-CN through =IF(CE2>0,((CE2+CE2)/2),"") etc...
    The working result is now:
    Please Login or Register  to view this content.
    And it even works with named ranges.
    If you happen to have a suggestion to overcome the formatting incompatibility, then great - otherwise the current set-up will do.
    Will mark this one as solved now.

    Quote Originally Posted by daddylonglegs View Post
    Using SUMPRODUCT is OK if you can be sure you have only one row which matches the criteria - if you might have more than one row which satisfies the conditions (or no rows) then you might get odd results. Try this array formula to give you the column A value for the first instance

    =INDEX(Sheet1!$A$2:$A$60,SMALL(IF((Sheet1!$CE$2:$CN$60=Sheet2!D2)*(Sheet1!$AN$2:$AN$60="no")*(Sheet1!D2:D60=Sheet2!F2),ROW(Sheet1!$A$2:$A$60)-ROW(Sheet1!$A$2)+1),1))

    confirmed with CTRL+SHIFT+ENTER

    If there are no matches you get #NUM! error
    Thank you for the suggestion. As Sheet2!F2 is the outcome of {=MAX(IF(COUNTIF(Sheet2'!D2,'Sheet1'!$CE$1:$CN$50),IF(Sheet1'$AR$1:$AR$50="No", 'Sheet1'!$D$1:$D$50))} there will always be only one row matching the criteria.
    However, I did test your proposed formula in my sample file which worked well, but then in my 'production' file, packed with data, the array formula provided some odd results (i.e. row entries above the desired row, which I could not easily correct by adjusting the row reference in the formula). Hence my preference to go with JBeaucaire's solution.

    Many thanks to all for your time and knowledge - much appreciated!
    Last edited by 0Twintig; 09-03-2013 at 01:08 PM.

  18. #18
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Lookup value from range for corresponding row where multiple criteria are met

    Maybe: Sheet1!$CO$2:$CX$6000&""=Sheet2!D2


    Or...whatever formula is IN CE:CN add a +0 to the end of the formula.

    =YourFormula+0

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel Lookup with multiple criteria and date range match
    By denniswtlx in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-06-2013, 02:25 PM
  2. [SOLVED] Lookup Multiple criteria with range
    By serene11111 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-21-2013, 02:36 AM
  3. Replies: 10
    Last Post: 02-19-2013, 12:05 PM
  4. Replies: 11
    Last Post: 02-07-2013, 02:22 AM
  5. Replies: 1
    Last Post: 05-16-2011, 05:00 PM

Tags for this Thread

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