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
 
Hello,

Welcome to the forums! :)

Well you have a couple of options at this point. The first is convert the returns to Values, and use Text to Columns, using the comma and space as a delimeter.

Perhaps not reliable, pending what your data return is. I wrote two procedures to loop through a list and parse out multiple returns to individual cells across columns, here:

http://www.mrexcel.com/board2/viewtopic.php?p=1399966#1399966

Perhaps that will help.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Thanks for the link. I will try to make sense of them!

I did look at the option of converting to values and then converting text to columns. I was trying to record a macro to do this, but I need it to automatically change when a user changes the lookup value. I also looked at the advanced filter, but i had the same problem of automatically changing.

There is probably a much easier way of doing the overall calculations i am trying to do, but if i put that on here, someone'd be doing my work for me.

thanks.
 
Upvote 0
Here's what you really need to consider:

Code:
Set rngIn = Range("D1:E16") 
Let arrLoopList = Range("F1:F5").Value
D1:D16 houses the values to looked up, E1:E16 houses the corresponding values. F1:F5 houses the values you're searching for.

The problem with a UDF/Worksheet function solution is that it's pretty gratuitous use of expensive functions if you have a lot of potential columns and they're not needed.

To have this update in the event that someone changes the Lookup data or whatnot, you'll have to use a Worksheet Change event that calls foobar. See the following:

http://www.cpearson.com/excel/Events.aspx
 
Upvote 0
Thanks again! I finally figured out that what you posted was a Macro and not a Function. duh. As I said, I'm not a programmer, and am sorta winging all this excel programming stuff. That macro works great, thank you. I may just make the users run it when they change stuff. at least for the time being, and do that event thing you mentioned later.

thanks again for your help.
 
Upvote 0
Hello,
I am new to this forum. I checked a bit the previous posts and I saw that the script that was given is for returning multiple rows. I was wondering if I can do the same for columns.
I am using now the function: =VLOOKUP($A$1:$A$2430,$B:$Y,1,0) and I want from these Lookup to be returned not only column 1(column B) but columns 1-24 (columns B-X). (the first picture is the data, the second what I want to do with the Vlookup)

c:\excel.JPG

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype>

c:\excel2.JPG

Is it possible? any help?
thanks!
 
Last edited:
Upvote 0
Holy Bogart! I'm not sure of posting etiquette but I would guess that since my issue pertains to this issue, it is best posted here. I don't want to "jack" a thread... If that is what I am doing I will remove this post and start my own thread.

Both Jon's macro and Nate's Function almost do what I need. I guess I prefer the macro cause it's automatic and I figured out how to pull more than just the title (I'm trying to query more than just 1 piece of info. I need it to return 3 different values per Author (ex: Title, Price & Publisher)). I'll keep with this example for sake of ease.

Here is my question:

Is there some way to adjust the macro so that is will pull the info for multiple Author entries? If not, is there a way to "unjoin" Nate's function and have it insert the book titles in their own cells?

Ex: If I have a list of Authors, I would like to be able to paste the list in column A and get the info back for each Author.

I paste in :
PERSONAL.xls
ABCD
1Field1Field2Field3Field4
2AAA
3XXX
4
Sheet1


I would like to get:
PERSONAL.xls
ABCD
1Field1Field2Field3Field4
2AAAF1F2F3
3F1AF2AF3A
4F1BF2BF3B
5XXX123
6456
Sheet1
 
Upvote 0
Hello,

Select the column, copy and paste as values. Click Data->Text to Columns... Use comma and space as your delimters, check the consecutive delimeters option. This will unjoin my data return in a hurry.

You can record this code too, if you want it fully automated in a procedure.

Space might not work if your data has spaces in them, rewrite my function, change this:

Join$(newArr, ", ")

To this:

Join$(newArr, ",")

Then just use a comma as your delimter.
 
Upvote 0
Is there an inexpensive way to return only UNIQUE values?

I want to return all unique values (possible mutliple returns) but not repeat the same value.

Also is this any faster?
Code:
'Vlookup Multiple Criteria
'Returns all values matching vlookup criteria, separated by a comma
'=mvlookup(a1,sheet2!$a$1:$c$999,3)
Function mvlookup(lookupValue, tableArray As Range, colIndexNum As Long, _
Optional NotUsed As Variant) As Variant
Dim initTable As Range
Dim myRowMatch As Variant
Dim myRes() As Variant
Dim myStr As String
Dim initTableCols As Long
Dim i As Long
Dim ubound_myRes As Long
Set initTable = Nothing
On Error Resume Next
Set initTable = Intersect(tableArray, _
tableArray.Parent.UsedRange.EntireRow)
On Error GoTo 0
If initTable Is Nothing Then
mvlookup = CVErr(xlErrRef)
Exit Function
End If
initTableCols = initTable.Columns.Count
i = 0
Do
myRowMatch = Application.Match(lookupValue, initTable.Columns(1), 0)
If IsError(myRowMatch) Then
Exit Do
Else
i = i + 1
ReDim Preserve myRes(1 To i)
myRes(i) _
= initTable(1).Offset(myRowMatch - 1, colIndexNum - 1).Text
If initTable.Rows.Count <= myRowMatch Then
Exit Do
End If
On Error Resume Next
Set initTable = initTable.Offset(myRowMatch, 0) _
.Resize(initTable.Rows.Count - myRowMatch, _
initTableCols)
On Error GoTo 0
If initTable Is Nothing Then
Exit Do
End If
End If
Loop
If i = 0 Then
mvlookup = CVErr(xlErrNA)
Exit Function
End If
myStr = ""
For i = LBound(myRes) To UBound(myRes)
myStr = myStr & ", " & myRes(i)
Next i
mvlookup = Mid(myStr, 3)
End Function
 
Upvote 0
Bump-

Looking for vlookup to return multiple returns in one cell as the above functions do...but ONLY unique values...
Here is code that does it across multiple cells---can't figure out how to return in one cell, separating values by ",":
Code:
Function VLookups(lookupValue, lookupArray, ColumnNumber)
'This function acts somewhat like the built-in VLookup
'Function with exact matches, except that it returns an
'array of all the values corresponding to multiple
'occurrences of the sought value in the left hand column
'(i.e., the first column vector in the lookup array). The
'function is not presently case sensitive.
    Dim arr, outputArrayVLookups, tempArrayVLookups, col1 As Variant
    Dim p As Long, i As Long, m As Long, j As Integer
    Dim present As Boolean
    present = False
 
    'Assign to a variable the left hand column
    col1 = Application.Index(lookupArray, 0, 1)
 
    'Assign to a variable the number of ocurrences
    'of the lookup value
    p = ArrayCountIf(col1, lookupValue)
 
    If TypeOf Application.Caller Is Range Then
        If p = 0 Then
            VLookups = CVErr(xlValue)
            Exit Function
        End If
    Else
        If p = 0 Then
            VLookups = [#Value!]
            Exit Function
        End If
    End If
 
    'resize the array of index values to accommodate
    'the number of occurrences of the lookup value
    ReDim tempArrayVLookups(1 To p, 1 To 2)
 
    'Loop to load the array of indexes of lookup
    'values; each instance of a lookup value is
    'changed so that the Match Function will not
    'find it a second time.
    For m = 1 To p
        i = Application.Match(lookupValue, col1, 0)
        If Application.Proper(col1(i, 1)) = Application.Proper(lookupValue) Then
            tempArrayVLookups(m, 1) = i
            tempArrayVLookups(m, 2) = 1
            col1(i, 1) = "yyzz"
        Else
            m = m - 1
            col1(i, 1) = "yyzz"
        End If
    Next
    If IsArray(ColumnNumber) Then
        NumCols = UBound(ColumnNumber) - LBound(ColumnNumber) + 1
        ColNumArray = True
    End If
    If TypeName(lookupArray) = "Range" Then
        If lookupArray.Areas.Count > 1 Then VLookups = "A range input must be a single-area range": Exit Function
    End If
 
    If TypeOf Application.Caller Is Range Then
        iRows = Range(Application.Caller.Address).Rows.Count
        iCols = Range(Application.Caller.Address).Columns.Count
        If ColNumArray Then
            If InStr(1, Application.Caller.FormulaArray, "vlookups") = 2 Then
                If iCols < NumCols Or iRows < p Then
                 VLookups = "Select at least " & p & " row(s) and " & NumCols & " column(s)."
                    Exit Function
                End If
            End If
        ElseIf iRows < p Then
            If InStr(1, Application.Caller.FormulaArray, "vlookups") = 2 Then
                VLookups = "Select at least " & p & " row(s)."
                Exit Function
            End If
        End If
 
        'Loop to load the array of values corresponding to the
        'multiple occurrences of lookup value, i.e., the output
        'array. Provision is made for returning multiple values
        'corresponding to a single occurrence of lookupValue;
        'i.e., for calling this function with, e.g.,
        '=VLookups(lookupValue, lookupArray, {2,4,5})
        If Not ColNumArray Then
            ReDim outputArrayVLookups(1 To Application.Max(iRows, p), 1 To iCols)
            For i = 1 To Application.Max(iRows, p)
                For j = 1 To iCols
                    If i > p Or j > 1 Then
                        outputArrayVLookups(i, j) = ""
                    Else
                        outputArrayVLookups(i, j) = lookupArray(tempArrayVLookups(i, j), ColumnNumber)
                    End If
                Next
            Next
        Else
            ReDim outputArrayVLookups(1 To Application.Max(iRows, p), 1 To iCols)
            For i = 1 To iRows
                For j = 1 To iCols
                    If j > NumCols Or i > p Then
                        outputArrayVLookups(i, j) = ""
                    Else
                        outputArrayVLookups(i, j) = lookupArray(tempArrayVLookups(i, 1), ColumnNumber(j))
                    End If
                Next
            Next
        End If
    Else
        'Loop to load the array of values corresponding to the
        'multiple occurrences of lookup value, i.e., the output
        'array. Provision is made for returning multiple values
        'corresponding to a single occurrence of lookupValue;
        'i.e., for calling this function with, e.g.,
        '=VLookups(lookupValue, lookupArray, {2,4,5})
 
        If Not ColNumArray Then
            ReDim outputArrayVLookups(1 To p, 1 To 1)
            For i = 1 To p
                For j = 1 To 1
                    outputArrayVLookups(i, j) = lookupArray(tempArrayVLookups(i, j), ColumnNumber)
                Next
            Next
        Else
            ReDim outputArrayVLookups(1 To p, LBound(ColumnNumber) To UBound(ColumnNumber))
            For i = 1 To p
                For j = LBound(ColumnNumber) To UBound(ColumnNumber)
                    outputArrayVLookups(i, j) = lookupArray(tempArrayVLookups(i, 1), ColumnNumber(j))
                Next
            Next
        End If
    End If
VLookups = outputArrayVLookups
End Function
 
Upvote 0

Forum statistics

Threads
1,215,921
Messages
6,127,711
Members
449,399
Latest member
VEVE4014

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