Lookup with multiple matches in one cell

jono67

New Member
Joined
Mar 28, 2007
Messages
3
Hello,
I`m looking for a formula like =LOOKUP("F";B1:B7;A1:A7) that returns all matches in one cell, not only the first.

Formula needed for result like B10 to B12

A B
1 member1 F
2 member2 S
3 member3 N
4 member4 F
5 member5 S
6 member6 N
7 member7 F
8
9
10 F member1, member4, member7
11 S member2, member5
12 N member3, member6

Thanks /Joe
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi Joe
Welcome to the board

If you want the solution in the format you posted, a csv string, you have to use vba (yours or an add-in).

You can have a formula solution if it's OK to you to have each value in a different cell (like in the example the values for F in B10, C10 and D10).

Post back your decision.

Kind regards
PGC
 
Upvote 0
Hi,
thanks for your quick reply.
As I have to do this on a big list, I will have problems to define cellgroups that are big enough to display all results.
So, I guess, the csv string is neccessary.

Thanks /Joe
 
Upvote 0
Hi again

Assuming the data in A:B starting in row 1 like in the worksheet I post, try:
Code:
Sub BuildCSV()
Dim rRng As Range, rCell As Range
Dim vResult, lRow As Long

Set rRng = Range("B1", Range("B" & Rows.Count).End(xlUp))

With CreateObject("Scripting.Dictionary")
    For Each rCell In rRng
        If .exists(rCell.Value) Then
            .Item(rCell.Value) = .Item(rCell.Value) & "," & rCell.Offset(, -1)
        Else
            .Add rCell.Value, rCell.Offset(, -1).Value
        End If
    Next rCell
    
    ReDim vResult(1 To .Count, 1 To 2)
    For Each vkey In .keys
        lRow = lRow + 1
        vResult(lRow, 1) = vkey
        vResult(lRow, 2) = .Item(vkey)
    Next vkey

End With

Application.ScreenUpdating = False
Range("D1").Resize(UBound(vResult), 2) = vResult
Application.ScreenUpdating = True

End Sub

Remarks:
- As you see I build the result in memory (using the array) before writing to the worksheet. This is because you say you have a big list. It's faster this way.
If the list is not that big, you can lose the array and write directly in the worksheet.
- I assumed there is nothing below the list in columns A:B

Hope this helps
PGC
Booky.xls
ABCDEF
1Member1AAMember1,Member7,Member9,Member14,Member20,Member25
2Member2DDMember2,Member4,Member5,Member8,Member12,Member18,Member22
3Member3CCMember3,Member6,Member15,Member17,Member23,Member24
4Member4DBMember10,Member11,Member13,Member16,Member19,Member21
5Member5D
6Member6C
7Member7A
8Member8D
9Member9A
10Member10B
11Member11B
12Member12D
13Member13B
14Member14A
15Member15C
16Member16B
17Member17C
18Member18D
19Member19B
20Member20A
21Member21B
22Member22D
23Member23C
24Member24C
25Member25A
26
Sheet1
 
Upvote 0
type or copy unique values down the data
see the sample sheet below (IN THIS SHEET UNIQUE VALUES ARE TYPED a15 TO a17. modify to suit you. the results are in B15 to B17
Book1
ABCD
1hdng1hdng2
2member1F
3member2S
4member3N
5member4F
6member5S
7member6N
8member7F
9
10
11
12
13
14
15FFmember1member4member7
16NNmember3member6
17SSmember2member5
Sheet1



the run the macro given below
Code:
Option Explicit

Sub test()
Dim rng, cfind, rng1, c As Range
Dim i, ilookup As Integer
Dim mmatch As String
mmatch = ""
Set rng = Range("B1:B8") ' modify to suit
Set rng1 = Range("a15:a17")
Set cfind = Range("B1")
For Each c In rng1
ilookup = WorksheetFunction.CountIf(rng, c)
'MsgBox ilookup
For i = 1 To ilookup
Set cfind = rng.Find(what:=c, lookat:=xlWhole, after:=cfind)
'MsgBox cfind.Address
mmatch = mmatch & " " & cfind.Offset(0, -1).Value
'MsgBox mmatch
Next i
c.Offset(0, 1) = cfind & mmatch
mmatch = ""
Next c
End Sub

MODIFY THE MACRO TO SUIT YOUR DATA
 
Upvote 0
Hello all,
thanks for your replies!
Your scripts brought us to the right direction!
We are working on the modification...

Kind regards /Joe
 
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,946
Members
449,480
Latest member
yesitisasport

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