+ Reply to Thread
Results 1 to 25 of 25

vlookup with conditions to find multiple entries

  1. #1
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    vlookup with conditions to find multiple entries

    Hello,

    I am new to excel and am struggling with vlookup. I have looked at various posts regarding vlookup but couldn't successfully use it to find a solution to my problem. The below is the description of my problem. I have a table (table1) with material numbers which have a price . This value is time dependent i.e., a material 999 could have a price of $10 for 1/1/2008-1/15/2008 and $20 for 1/16/1008 - 1/31/2008.

    A B C D
    999 1/1/2008 1/15/2008 $10
    999 1/15/2008 1/31/2008 $20
    998 2/1/2008 - 2/25/2008 $15

    I have another table (table2) in another sheet in the same workbook have a material and date.

    A B C
    999 1/10/2008
    999 1/20/2008
    998 2/15/2008

    My requirement to take the material value and date in table2 and match it with table1 and get the value of column D in table 1 to column C of table2.

    I have tried using vlookup but it only works for the first match and doesn't check for other values

    below is the function that i tried

    =if(and(vlookup(A2,Sheet2!A1:D4,2,false)<=Sheet1!B2,vlookup(Sheet1!A2,Sheet2!A2:D4,3,false)>=Sheet1!C2)),vlookup(Sheet1!A2,Sheet2!A2:D4,4,false),"error")

    Can anyone please help me with this problem.
    Last edited by excelnerd1; 02-05-2009 at 03:17 PM. Reason: new questions regarding the same problem

  2. #2
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: vlookup with conditions to find multiple entries

    Use Sumproduct or SUM array fucntion it will be easier than vlookup...

    Post the spreadsheet for exact formula


    Please Login or Register  to view this content.
    Last edited by Shijesh Kumar; 02-02-2009 at 02:49 PM.

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

    Re: vlookup with conditions to find multiple entries

    Assuming you don't have overlapping ranges (not categorically clear based on sample data)

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 02-02-2009 at 02:49 PM.

  4. #4
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: vlookup with conditions to find multiple entries

    Below is the corrected sample worksheet.

    [ATTACH]example1.xls[/ATTACH]
    Last edited by excelnerd1; 02-02-2009 at 03:04 PM. Reason: wrong data in the attached sheet

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

    Re: vlookup with conditions to find multiple entries

    This requires a lengthy sumproduct formula:

    =SUMPRODUCT(--(Sheet2!$A$2:$A$10=A2),--(Sheet2!$B$2:$B$10<=B2),--(Sheet2!$C$2:$C$10>=B2),(Sheet2!$D$2:$D$10))

    There is a date range error in your data for 997.
    Last edited by JBeaucaire; 02-02-2009 at 02:58 PM.
    _________________
    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!)

  6. #6
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: vlookup with conditions to find multiple entries

    Please Login or Register  to view this content.
    copy the above formula in C2 and drag it down
    Last edited by Shijesh Kumar; 02-02-2009 at 03:02 PM.

  7. #7
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: vlookup with conditions to find multiple entries

    thank you so much for your quick replies. But i am not sure how sumproduct will help with my problem. Please refer to the sample spredsheet that i posted. I am trying to do a lookup to another sheet based on the values in my first sheet. i.e., in order to retreive the correct amount i have to first match the materail and then see if the date falls in the date range and if all these conditions are true then get the amount value. Hope i am clear.

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

    Re: vlookup with conditions to find multiple entries

    JB, although it makes no difference to the functionality of the formula you need not encase the Sum range within parentheses.
    Last edited by DonkeyOte; 02-02-2009 at 03:02 PM.

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

    Re: vlookup with conditions to find multiple entries

    Quote Originally Posted by DonkeyOte View Post
    JB, although it makes no difference to the functionality of the formula you need not encase with Sum range within parentheses.
    I know, I always have out of clarity (to me), probably always will. It's aesthetics, nothing more.

  10. #10
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: vlookup with conditions to find multiple entries

    Quote Originally Posted by excelnerd1 View Post
    thank you so much for your quick replies. But i am not sure how sumproduct will help with my problem. Please refer to the sample spredsheet that i posted. I am trying to do a lookup to another sheet based on the values in my first sheet. i.e., in order to retreive the correct amount i have to first match the materail and then see if the date falls in the date range and if all these conditions are true then get the amount value. Hope i am clear.

    Using vlookup for multiple criteria is very complicated.
    Using sumproduct is a alternate and very efficient way


    Column C with ID 997 has start date 2/1/2008 and end date 1/28/2008 ??? howz this
    Last edited by Shijesh Kumar; 02-02-2009 at 03:07 PM.

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

    Re: vlookup with conditions to find multiple entries

    Quote Originally Posted by excelnerd1 View Post
    thank you so much for your quick replies. But i am not sure how sumproduct will help with my problem. Please refer to the sample spredsheet that i posted. I am trying to do a lookup to another sheet based on the values in my first sheet. i.e., in order to retreive the correct amount i have to first match the materail and then see if the date falls in the date range and if all these conditions are true then get the amount value. Hope i am clear.
    Properly formatted, the multiple comparison criteria eventually filter down to a single matching row. We just have to use enough comparisons to get that to happen.

    If no comparisons result, you get an error, like your sample sheet has an error on the date ranges you input for 997, so that one would never give you an answer.

    Although that's a bad thing, it proves conclusively the Sumproduct approach is what will work.

  12. #12
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: vlookup with conditions to find multiple entries

    thank you so much JB the formula worked. I can't thank you enough.

  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: vlookup with conditions to find multiple entries

    Everyone here came to the same conclusion, so cheers to the whole gang, eh?

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

    Re: vlookup with conditions to find multiple entries

    timing...nvm.

  15. #15
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: vlookup with conditions to find multiple entries

    yes, you are right JB. Thank you all so much, I have been trying to solve this problem for so long and this forum was my last hope and it did come to my rescue.

  16. #16
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: vlookup with conditions to find multiple entries

    Hello all,

    Since I got the solution to the for the problem i was having i have been playing with it a lot, i came across another problem, for some reason this formula doesn't seem to work when the ranges fall in 2 different years. Please look at the attached example. Material 999 has values of 10, 20 for ranges 1/1/2008 1/31/2009 - 10
    2/1/2009 12/31/9999 - 20

    The sum product formula doesn't seem to working for this. Can you please help.:

    example1.xls
    Last edited by excelnerd1; 02-05-2009 at 03:31 PM.

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

    Re: vlookup with conditions to find multiple entries

    You have data inconsistencies. I converted all the entries to actual dates and it started working, though your date in C3 had a year of 9999 so that won't work.

    Anyway...
    Attached Files Attached Files

  18. #18
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: vlookup with conditions to find multiple entries

    Please don't ask a question on an existing thread and then start a new thread with the same question...it wastes people's time!
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  19. #19
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: vlookup with conditions to find multiple entries

    JBEAUCAISE

    Can you please send me the corrected sheet?

  20. #20
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: vlookup with conditions to find multiple entries

    sorry,

    say the attachment just now. thanks!

  21. #21
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: vlookup with conditions to find multiple entries

    JB, what data inconsistensies were there and how did you fix it? i am trying to make corrections to my original sheet just like the sample sheet you provided. Looks like i am completely lost.

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

    Re: vlookup with conditions to find multiple entries

    Text strings instead of dates. Take out the apostrophes:

    1/1/2009
    not
    '1/1/2009

    And the date in C3 had 9999 as a year, gotta fix that. Make sure the cells are formatted as Category: Date.

  23. #23
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: vlookup with conditions to find multiple entries

    Quote Originally Posted by excelnerd1 View Post
    JB, what data inconsistensies were there and how did you fix it? i am trying to make corrections to my original sheet just like the sample sheet you provided. Looks like i am completely lost.
    ...and if you read your other thread you started.. you would see that I did say the same thing... see what I mean about the time wasting?

  24. #24
    Registered User
    Join Date
    02-02-2009
    Location
    hhhh
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: vlookup with conditions to find multiple entries

    is there anyway to work with data with apostrophes? everytime I refresh the sheet with new data it get included with dates with apostrophes, is there any way i can overcome this?

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

    Re: vlookup with conditions to find multiple entries

    How is it being "refreshed". Can you correct the data as part of the "refresh" process? Macros can be instructed to correct these things. The data can all be highlighted and run an in-place Data>TextToColumns>Delimited>Date:MDY>Finish to correct the whole dataset at once.

+ 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