+ Reply to Thread
Results 1 to 8 of 8

Thread: lookup list

  1. #1
    Registered User
    Join Date
    01-18-2010
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2007
    Posts
    45

    lookup list

    I am trying to get excel to return a list of all vlookup results when there is more than 1 instead of just giving me an N/A result. Can I do that within vlookup or is there another way? See my attached example spreadsheet.
    Attached Files Attached Files
    Last edited by loner2003; 03-11-2010 at 11:20 AM. Reason: solved.

  2. #2
    Registered User
    Join Date
    12-30-2009
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: lookup list

    Would filtering by code 3 ultimately achieve what you are looking for?

  3. #3
    Registered User
    Join Date
    01-18-2010
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: lookup list

    That is really what I want to do, but I want it to occur automatically as a result of a user entry. So if a user inputs a value of 524210 for Code 3 (such as in a registration form where they would be answering questions and completing blank fields manually), I want the results of their entry to filter into a small chart of results that the user will be able to view.

  4. #4
    Registered User
    Join Date
    12-30-2009
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: lookup list

    I can't think of an easy way. I would most likely employ some code under this circumstance.

  5. #5
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: lookup list

    Normally you would have a construction like
    HTML Code: 
    =INDEX($B$2:$B$16,Match(524210,$E$2:$E$16,0),1)
    if it was a single (first) lookup. As it is the Nth I would use
    HTML Code: 
    =INDEX($B$2:$B$16,NthMatch(524210,$E$2:$E$16,2),1)
    Where this is the code
    Option Explicit
    
    Function NthMatch(Val, MyRng As Range, Nth As Long) As Long
    
    Dim NthCounter As Long
    
    If MyRng.Cells.Count < 1 Then Exit Function
    If MyRng.Columns.Count <> 1 Then Exit Function
    If IsEmpty(Val) Then Exit Function
    If IsEmpty(Nth) Then Exit Function
    If Nth > Application.WorksheetFunction.CountIf(MyRng, Val) Or _
             Application.WorksheetFunction.CountIf(MyRng, Val) = 0 Then Exit Function
    
    For NthMatch = 0 To MyRng.Cells.Count
      If MyRng(NthMatch, 1) = Val Then NthCounter = NthCounter + 1
      If NthCounter = Nth Then Exit Function
    Next NthMatch
    
    End Function
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  6. #6
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: lookup list

    On the Ozgrid they tackle it as such:
    Function Nth_Occurrence(range_look As Range, find_it As String, _
      occurrence As Long, offset_row As Long, offset_col As Long)
    
    Dim lCount As Long
    Dim rFound As Range
    
      Set rFound = range_look.Cells(1, 1)
        For lCount = 1 To occurrence
          Set rFound = range_look.Find(find_it, rFound, xlValues, xlWhole)
        Next lCount
        Nth_Occurrence = rFound.Offset(offset_row, offset_col)
    End Function
    Your use: =Nth_Occurrence($E$2:$E$16, "524210", 1, 0, -3)

    http://www.ozgrid.com/Excel/find-nth.htm
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  7. #7
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: lookup list

    In this type of setup any formula based approach is always going to be messy and is unlikely to offer the same flexibility of a UDF - this is partly down to the layout of the source data.

    Golden rule is to avoid repetitive calculations and that will be adopted in below.

    If we assume for sake of argument / demo that using the sample file B21 holds code3 of interest: 524210

    First - identify the number of records that should be returned in results table:

    C21: =COUNTIF($E$1:$E$16,$B21)
    In this case that will be 2.

    Next - identify the row(s) on which the n instances are to be found:

    A23: =IF(ROWS($A$23:A23)>$C$21,"",MATCH(1,INDEX(($E$1:$E$16=$B$21)*(ROW($E$1:$E$16)>N($A22)),0),0))
    copied down to A27
    if preferred you could use a SMALL Array
    (I used 27 to account for possibility of 5 matches - you should adjust as neccessary)

    We use A23:A27 to generate the results table (specifically to avoid [expensive] repetitive calcs)

    B23: 
    =IF($A23="","",LOOKUP(REPT("Z",255),$A$1:INDEX($A:$A,$A23)))
    copied down to B27
    
    C23:
    =IF($A23="","",INDEX($B:$B,$A23))
    copied down to C27

    Changing B21 to 531120 you should get 5 records returned
    Last edited by DonkeyOte; 03-11-2010 at 08:27 AM. Reason: Ricardo pointed out typo in my COUNTIF range (E not C) - thanks Ricardo :)

  8. #8
    Registered User
    Join Date
    01-18-2010
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: lookup list

    Thanks all. SOLVED.

+ 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.2.0