Vlookup and return multiple values horizontally

galmond1010

New Member
Joined
Apr 15, 2019
Messages
21
I have PARTS listed in column A and CUSTOMER NAMES in column C. I need to look up column A and return all customers associated with a PART and display it horizontally.
Any help would be greatly appreciated.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I put the part to find in D1, then ran this macro to show the customers starting in E1:

Code:
Sub PartCust()
Dim cp As Integer, cn As Integer, LR As Long, i As Integer
LR = Cells(Rows.Count, "A").End(xlUp).Row
cp = WorksheetFunction.CountIf(Range("A:A"), Range("C1"))
cn = 5
For i = 2 To LR
  If Range("A" & i) = Range("D1") Then
  Cells(1, cn) = Range("C" & i)
  cn = cn + 1
  Else
  End If
Next i
End Sub

Rerunning this would require clearing E1:Z1, for example.

Code:
Sub PartCust()
Dim cp As Integer, cn As Integer, LR As Long, i As Integer
LR = Cells(Rows.Count, "A").End(xlUp).Row
Range("E1:Z1").ClearContents
cp = WorksheetFunction.CountIf(Range("A:A"), Range("C1"))
cn = 5
For i = 2 To LR
  If Range("A" & i) = Range("D1") Then
  Cells(1, cn) = Range("C" & i)
  cn = cn + 1
  Else
  End If
Next i
End Sub
 
Last edited:
Upvote 0
How about


Book1
ACDEFGHI
1CountyWard
2CambridgeshireDownham VillagesDorsetPoole TownParkstoneTown Centre
3NorfolkUpwell and Delph
4East Riding of YorkshireKings Park
5East Riding of YorkshireSutton
6CambridgeshireRoman Bank
7KentWalland & Denge Marsh
8DorsetPoole Town
9Greater LondonThamesmead Moorings
10Greater LondonAbbey Wood
11Greater LondonThamesmead East
12Greater LondonEvelyn
13DevonTeignmouth East
14DorsetParkstone
15DorsetTown Centre
16East SussexDevonshire
Sheet2
Cell Formulas
RangeFormula
G2=IFERROR(INDEX($C$2:$C$37,AGGREGATE(15,6,(ROW($A$2:$A$37)-ROW($A$2)+1)/($A$2:$A$37=$F2),COLUMNS($A$1:A$1))),"")

Formula in G2 copied to the right
 
Upvote 0
Try this array formula.
Put the clients in column D, copy the formula to the right and down.


<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:76.04px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td><td >C</td><td >D</td><td >E</td><td >F</td><td >G</td><td >H</td><td >I</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td style="background-color:#b2a1c7; ">Parts</td><td style="background-color:#b2a1c7; ">customer</td><td > </td><td style="background-color:#b2a1c7; ">customer</td><td style="background-color:#b2a1c7; ">Part</td><td style="background-color:#b2a1c7; ">Part</td><td style="background-color:#b2a1c7; ">Part</td><td style="background-color:#b2a1c7; ">Part</td><td style="background-color:#b2a1c7; ">Part</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td >a</td><td style="background-color:#ffff00; ">cust1</td><td > </td><td style="background-color:#ffff00; ">cust1</td><td >a</td><td >e</td><td >i</td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td >b</td><td style="background-color:#92d050; ">cust2</td><td > </td><td style="background-color:#92d050; ">cust2</td><td >b</td><td >f</td><td >j</td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td >c</td><td >cust3</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td >d</td><td >cust4</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td >e</td><td style="background-color:#ffff00; ">cust1</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td >f</td><td style="background-color:#92d050; ">cust2</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td >g</td><td >cust3</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >9</td><td >h</td><td >cust4</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >10</td><td >i</td><td style="background-color:#ffff00; ">cust1</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >11</td><td >j</td><td style="background-color:#92d050; ">cust2</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >12</td><td >k</td><td >cust3</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b></b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >Formula</td></tr><tr><td >E2</td><td >{=IFERROR(INDEX($A$2:$A$12,SMALL(IF($B$2:$B$12=$D2,ROW($B$2:$B$12)-1),COLUMNS($E$1:E1))),"")}</td></tr></table></td></tr></table>
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Fluff-
I re-created what you have above and I am getting a 0 in cell F2. When copying the formula over to the right and down, I get a 0 as a return. Thoughts? The example you have above is exactly what I am trying to accomplish. Thanks again.
 
Last edited:
Upvote 0
You need to manually input the value in F2 for the formula to work off.
If you want a formula to create as list of unique values use
=IFERROR(INDEX($A$2:$A$37,MATCH(0,INDEX(COUNTIF($F$1:$F1,$A$2:$A$37),0),0)),"")
In F2 downwards with the other formula in G2
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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