Vlookup with multiple results

dsrt16

Board Regular
Joined
Jun 18, 2005
Messages
208
I am creating a database with authors, book titles, descriptions, and prices. When I type in a specific authors name in cell C3 I need all the titles in the datbase to appear. I know how to get one to do so, but not all of them.

=VLOOKUP(C3,Book List!A5:D563,2,FALSE) will return one of the book titles.

I have a table set up on the Book List worksheet with author, book title, desciption, and price. I have it set up where I only type the authors name once in the first column then in the second column I list their book titles. After listing their titles then I move on to the next author like this:

Then when I enter Name of Author in cell C3 I want cell C5 to list all the books of that author. (aka A fun title, Another Title, Yeah).
However with the formula I have above it will just list the first title. (aka A fun title)

Edited by NateO: Tried to clean up the table.

Edited by NateO, again: Nope, not working. Deleted the table. You might be interested in the HTML Maker, here:

http://www.puremis.net/excel/downloads.shtml
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Whicever is easiest to learn and implement. I must admit I am unsure what VBA code solutions are.
 
Upvote 0
Can you post a small sample of the data you need to pull from, as well as which field you will use as a search criteria.
 
Upvote 0
Authors List.xls
ABCD
4AuthorTitleReadDescription
5Abramson,TraciHunterUndercurrents
6RippleEffects
7
8Allen,NancyCambellAtimefortheHeart
9Echoes
10LoveBeyondTime
11NoTimeforLove
12FaithofourFathers1
13FofF2
14FofF3
15FofF4
16
17Anderson,C.PaulFinalAct
Sheet1


Now in another worksheet (in cell C3) when I type Abramson, Traci Hunter I want it to list in cell C5 Undercurrents and Ripple Effects. When I type in Bell, Michele Ashman I want it to list all 8 of her books in cell C5.
 
Upvote 0
Here's a code-based solution.

You would enter your target value in cell A2 on this sheet
Book3
ABCDE
1Field1Field2Field3Field4
2AAAF1F2F3
3F1AF2AF3A
4F1BF2BF3B
5
Sheet1


And the results you see in columns B:D above should pop in from this sheet.
Book3
ABCDE
1Field1Field2Field3Field4
2AAAF1F2F3
3AAAF1AF2AF3A
4XXX123
5AAAF1BF2BF3B
6XXX456
7
Sheet2


Here's the code that does that.<font face=Courier New><SPAN style="color:#00007F">Private</SPAN><SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target<SPAN style="color:#00007F">As</SPAN> Range)<SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Not</SPAN> Intersect(Target, [A2])<SPAN style="color:#00007F">Is</SPAN><SPAN style="color:#00007F">Nothing</SPAN><SPAN style="color:#00007F">Then</SPAN>
    Application.EnableEvents =<SPAN style="color:#00007F">False</SPAN>
    Application.ScreenUpdating =<SPAN style="color:#00007F">False</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> LastUsed<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN>
    LastUsed = Cells(Rows.Count, 2).End(xlUp).Row
    Range("B1:D" & LastUsed).Clear
    <SPAN style="color:#00007F">With</SPAN> Sheet2
        .Columns("A:D").AutoFilter Field:=1, Criteria1:=Target.Value
        .[B:D].Copy [B1]
        .Cells.AutoFilter
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">With</SPAN><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
Application.EnableEvents =<SPAN style="color:#00007F">True</SPAN>
Application.ScreenUpdating =<SPAN style="color:#00007F">True</SPAN><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Sub</SPAN></FONT>

Hit Alt+F11 to open the VB Editor; on the left hand side, find the sheet name for the sheet on which you want to enter the A2 value.

Click it so it is selected. There should be a big white spae i the center/right of your screen.

Highlight the code above with your cursor, copy and paste in into that white space.

You can now close the Editor. Any change to cell A2 on that sheet should re-seed your other columns.

From now on, when opening the workbook, you'll get a warning that it contains macros -- if you want the code to work, you must answer in the affirmative.

Post back if you have trouble.
 
Upvote 0
Hello,

dsrt16 said:
aka A fun title, Another Title, Yeah
{snip}

Here's another potential approach. Use the following UDF, place it in a normal module in your workbook:

Code:
Public Function foo( _
    ByRef rngIn As Range, ByRef nameIn As String) As String

Dim tmpArr() As Variant

With WorksheetFunction
    Let tmpArr = .Transpose( _
        Evaluate("" & rngIn.Columns(1).Address & "&" _
        & rngIn.Columns(2).Address & ""))
    Let foo = .Substitute(Join(Filter( _
        tmpArr, nameIn), ", "), nameIn, vbNullString)
End With
End Function

And use in your workbook as such:
Return all Matches.xls
ABCDE
1AuthorTitleName InReturn
2JoeBook1HaroldBook3, Book7, Book9
3TomBook2
4HaroldBook3
5HowardBook4
6JoeBook5
7TomBook6
8HaroldBook7
9HowardBook8
10HaroldBook9
SalaryCalc


And note, the filter() and Join() functions requires require XL 2000+, and that I have hardcoded to look at the 1st and 2nd column in a Range. :)


Edited by Nate: Removed harmless, but unecesssary space in UDF.
 
Upvote 0
WOw you guys are amazing I would love to be that good with Excel...someday when I am older :D.

Anyway, I am unsure how to implement your ideas. Alt F11 brought up the HTML maker and I was unsure where to paste the code that just jon gave me. I see where to put the foo formula of Nate's, but I do not know where to post the code.

Here is what I am trying to do:
Authors List.xls
ABCD
3SearchbyAuthorAllen,NancyCambell
4
5BookPriceDescription
6AtimefortheHeart#N/A#N/A
Sheet2


As you can see I am only getting one book result with the VLookup formula. I am positive your guys ideas will work but where do I paste thoe codes. What is really irritating me is C6 and D6 are displaying N/A when they should work as they refer to the book title (where there is only one--not many like the author) and it is just a simple vlookup code.
 
Upvote 0
Thanks, Jon. :)

dsrt16, the VBA UDF belongs in a normal module. Hit alt-f11 to open the VBE. Click Insert->Module and paste the code in the now opened, normal module.

Now go back to your worksheet and try foo() as posted earlier.

And, for future reference, to get rid of those chars in your HTML, see the following:

http://www.mrexcel.com/board2/viewtopic.php?t=92622#problems

Good hunting.
 
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top