Vlookup or other formula that can search and return multiple results?

andrew_milonavic

Board Regular
Joined
Nov 16, 2016
Messages
98
Hi,

Is there a way to have a formula (not VBA) search for “X” and return multiple results?

I made a sample with fake data to illustrate what I’m looking for.

[TABLE="class: grid, width: 500"]
<colgroup><col style="width:51pt" width="69" span="9"> </colgroup><tbody>[TR]
[TD="width: 69"] [/TD]
[TD="width: 69"]
[/TD]
[TD="width: 69"]Cats
[/TD]
[TD="width: 69"]Dogs [/TD]
[TD="width: 69"]Sheep[/TD]
[TD="width: 69"]Snakes[/TD]
[TD="width: 69"]insects[/TD]
[TD="width: 69"] [/TD]
[TD="width: 69"]Results:[/TD]
[/TR]
[TR]
[TD]Farm[/TD]
[TD] [/TD]
[TD]x[/TD]
[TD] [/TD]
[TD]x[/TD]
[TD]x[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Cats
[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Sheep[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Snakes[/TD]
[/TR]
</tbody>[/TABLE]


In my example, the formula would search 5 cells (horizontally) and the headings from the cells marked with an X would be returned as a result.
Hope this makes sense.

Thanks

Andrew
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
[TABLE="class: grid, width: 512"]
<tbody>[TR]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 64, bgcolor: transparent"]A[/TD]
[TD="width: 64, bgcolor: transparent"]B[/TD]
[TD="width: 64, bgcolor: transparent"]C[/TD]
[TD="width: 64, bgcolor: transparent"]D[/TD]
[TD="width: 64, bgcolor: transparent"]E[/TD]
[TD="width: 64, bgcolor: transparent"]F[/TD]
[TD="width: 64, bgcolor: transparent"]G[/TD]
[TD="width: 64, bgcolor: transparent"]H[/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]1[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 64, bgcolor: transparent"]Cats
[/TD]
[TD="width: 64, bgcolor: transparent"]Dogs
[/TD]
[TD="width: 64, bgcolor: transparent"]Sheep
[/TD]
[TD="width: 64, bgcolor: transparent"]Snakes
[/TD]
[TD="width: 64, bgcolor: transparent"]insects
[/TD]
[TD="width: 64, bgcolor: transparent"]Results:
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]2[/TD]
[TD="bgcolor: transparent"]Farm
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]x
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]x
[/TD]
[TD="bgcolor: transparent"]x
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]Cats
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]3[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]Sheep
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]4[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]Snakes
[/TD]
[/TR]
</tbody>[/TABLE]
This is an array formula and must be committed with CONTROL+SHIFT+ENTER. If done correctly Excel will put {} around the fourmula. copy down
Code:
=IF(ROWS($H$2:H2)>COUNTIF($C$2:$G$2,"x"),"",INDEX($C$1:$G$1,SMALL(IF($C$2:$G$2="x",COLUMN($C$2:$G$2)-COLUMN($C$2)+1),ROWS($H$2:H2))))
 
Upvote 0
Hey Scott,

Another quick question if you don't mind. If I want the results to be presented horizontally on the same row, in columns H,I,J how would the formula be changed?

thanks

Andrew
 
Upvote 0
Just change ROWS to COLUMNS and copy across. Still must use Ctrl+Shift+Enter
Code:
=IF([COLOR=#FF0000]COLUMNS[/COLOR]($H$2:H2)>COUNTIF($C$2:$G$2,"x"),"",INDEX($C$1:$G$1,SMALL(IF($C$2:$G$2="x",COLUMN($C$2:$G$2)-COLUMN($C$2)+1),[COLOR=#FF0000]COLUMNS[/COLOR]($H$2:H2))))
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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