Match data in 2 columns and return all results from a 3rd to a single cell
Hi all,
I have a spreadsheet that has 3 columns of data. I need to match results from 2 of the columns and return all the results from the corresponding 3rd column into a single cell. I have found some code that does this for a single search but I don't know how to expand this to search in an additional column. This code is below. Please could someone help?
Re: Match data in 2 columns and return all results from a 3rd to a single cell
Upload sample workbook, with desensitized raw data, along with expected output.
To attach a file, use "Go Advanced" button found at bottom right of edit/quick reply. Then click on "Manage Attachments" hyperlink. It will launch new window/tab.
"Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
― Robert A. Heinlein
Re: Match data in 2 columns and return all results from a 3rd to a single cell
Hi, ok thanks attachment uploaded.
In this file, columns F and G contain that data that will be looked up and matched in columns B and C and then output the corresponding matches from columns A into a single cell in column I. The data in A, B and C will be continually added to.
Sub Demo1()
Dim V, W, R&, K$
With Sheet1
V = .[F6].CurrentRegion.Value
W = .[A6].CurrentRegion.Value
With New Dictionary
For R = 1 To UBound(W)
K = W(R, 2) & " " & W(R, 3)
If .Exists(K) Then .Item(K) = .Item(K) & ", " & W(R, 1) Else .Item(K) = W(R, 1)
Next
For R = 1 To UBound(V): V(R, 1) = .Item(V(R, 1) & " " & V(R, 2)): Next
.RemoveAll
End With
.[I6].Resize(UBound(V)).Value = V
End With
End Sub
Do you like it ? So thanks to click on bottom left star icon « ★ Add Reputation » !
Re: Match data in 2 columns and return all results from a 3rd to a single cell
When I try and use this I get a compile error on New Dictionary. Did you manage to successfully run on the uploaded file? Should it go in thisworkbook or the sheet code?
Bookmarks