Vlookup --> find next

Sunvisor

Board Regular
Joined
Oct 9, 2009
Messages
233
Lets say you are using a vlookup to a value but there are multiple values with different results...

Is there a formula to do a vlookup and then in the row underneath say if vlookup = the above result, go to next?
 
See if this is what you had in mind.

Sheet1

*ABCDEF
*
*
***
***
***
****
****
****
****
****

<tbody>
[TD="bgcolor: #cacaca, align: center"]1[/TD]
[TD="align: center"]Item[/TD]
[TD="align: center"]Value[/TD]

[TD="align: center"]Lookup[/TD]
[TD="align: center"]Count[/TD]
[TD="align: center"]Value[/TD]

[TD="bgcolor: #cacaca, align: center"]2[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]23[/TD]

[TD="align: center"]X[/TD]
[TD="bgcolor: #ccffcc, align: center"]3[/TD]
[TD="bgcolor: #ccffcc, align: center"]34[/TD]

[TD="bgcolor: #cacaca, align: center"]3[/TD]
[TD="align: center"]X[/TD]
[TD="align: center"]34[/TD]

[TD="bgcolor: #ccffcc, align: center"]89[/TD]

[TD="bgcolor: #cacaca, align: center"]4[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]24[/TD]

[TD="bgcolor: #ccffcc, align: center"]82[/TD]

[TD="bgcolor: #cacaca, align: center"]5[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]64[/TD]

[TD="bgcolor: #ccffcc"]*[/TD]

[TD="bgcolor: #cacaca, align: center"]6[/TD]
[TD="align: center"]X[/TD]
[TD="align: center"]89[/TD]

[TD="bgcolor: #cacaca, align: center"]7[/TD]
[TD="align: center"]X[/TD]
[TD="align: center"]82[/TD]

[TD="bgcolor: #cacaca, align: center"]8[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]73[/TD]

[TD="bgcolor: #cacaca, align: center"]9[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]97[/TD]

[TD="bgcolor: #cacaca, align: center"]10[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]97[/TD]

</tbody>



You want to lookup all instances of X and return the corresponding values.

In the formulas I use the following defined named ranges:
  • Item
  • Refers to: =Sheet1!$A$2:$A$10
  • Value
  • Refers to: =Sheet1!$B:$B
Enter this formula in E2. This will return the count of records for the lookup value.

=COUNTIF(Item,D2)

Enter this array formula** in F2. This will extract the corresponding data for the lookup value.

=IF(ROWS(F$2:F2)>E$2,"",INDEX(Value,SMALL(IF(Item=D$2,ROW(Item)),ROWS(F$2:F2))))

Copy down until you get blanks.

** array formulas need to be entered using the key combination of CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the SHIFT key then hit ENTER.

I am currently using the above formula and it works great, but I need a bit of a hand to extend it:

What if column C now has additional Lookup values, so you want the results with X in column A AND E in Column C?

Sheet1

*ABCDEF
*
*
E**
***
***
E***
****
****
****
****

<tbody>
[TD="bgcolor: #CACACA, align: center"]1[/TD]
[TD="align: center"]Item[/TD]
[TD="align: center"]Value[/TD]

[TD="align: center"]Lookup[/TD]
[TD="align: center"]Count[/TD]
[TD="align: center"]Value[/TD]

[TD="bgcolor: #CACACA, align: center"]2[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]23[/TD]

[TD="align: center"]X AND E[/TD]
[TD="bgcolor: #CCFFCC, align: center"]2[/TD]
[TD="bgcolor: #CCFFCC, align: center"]34[/TD]

[TD="bgcolor: #CACACA, align: center"]3[/TD]
[TD="align: center"]X[/TD]
[TD="align: center"]34[/TD]

[TD="bgcolor: #CCFFCC, align: center"]89[/TD]

[TD="bgcolor: #CACACA, align: center"]4[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]24[/TD]

[TD="bgcolor: #CCFFCC, align: center"]*[/TD]

[TD="bgcolor: #CACACA, align: center"]5[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]64[/TD]

[TD="bgcolor: #CCFFCC"]*[/TD]

[TD="bgcolor: #CACACA, align: center"]6[/TD]
[TD="align: center"]X[/TD]
[TD="align: center"]89[/TD]

[TD="bgcolor: #CACACA, align: center"]7[/TD]
[TD="align: center"]X[/TD]
[TD="align: center"]82[/TD]

[TD="bgcolor: #CACACA, align: center"]8[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]73[/TD]

[TD="bgcolor: #CACACA, align: center"]9[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]97[/TD]

[TD="bgcolor: #CACACA, align: center"]10[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]97[/TD]

</tbody>


If that possible ?

Cheers - Rick
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
@Snupple

[Table="width:, class:grid"][tr][td]Row\Col[/td][td]
A​
[/td][td]
B​
[/td][td]
C​
[/td][td]
D​
[/td][td]
E​
[/td][td]
F​
[/td][/tr][tr][td]
1​
[/td][td]Item[/td][td]Value[/td][td][/td][td]Lookup[/td][td][/td][td]Count[/td][/tr]
[tr][td]
2​
[/td][td]A[/td][td]
23
[/td][td][/td][td]X[/td][td]E[/td][td]
2​
[/td][/tr]
[tr][td]
3​
[/td][td]X[/td][td]
34
[/td][td]E[/td][td][/td][td][/td][td]Value[/td][/tr]
[tr][td]
4​
[/td][td]C[/td][td]
24
[/td][td][/td][td][/td][td][/td][td]
34​
[/td][/tr]
[tr][td]
5​
[/td][td]B[/td][td]
64
[/td][td][/td][td][/td][td][/td][td]
34​
[/td][/tr]
[tr][td]
6​
[/td][td]X[/td][td]
89
[/td][td]E[/td][td][/td][td][/td][td]
34​
[/td][/tr]
[tr][td]
7​
[/td][td]X[/td][td]
82
[/td][td][/td][td][/td][td][/td][td]
34​
[/td][/tr]
[tr][td]
8​
[/td][td]A[/td][td]
73
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td]
9​
[/td][td]D[/td][td]
97
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td]
10​
[/td][td]C[/td][td]
97
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]


In F2 just enter:

=COUNTIFS(A2:A10,D2,C2:C10,E2)

In F4 control+shift+enter, not just enter, and copy down:

=IF(ROWS($F4:F4)>$F$2,"",INDEX($B$2:$B$10,SMALL(IF($A$2:$A$10=$D$2,IF($C$2:$C$10=$E$2,ROW($B$2:$B$10)-ROW($B$2)+1)),ROWS($F4:F4))))
 
Upvote 0
@Snupple

[TABLE="class: grid"]
<tbody>[TR]
[TD]Row\Col[/TD]
[TD]
A​
[/TD]
[TD]
B​
[/TD]
[TD]
C​
[/TD]
[TD]
D​
[/TD]
[TD]
E​
[/TD]
[TD]
F​
[/TD]
[/TR]
[TR]
[TD]
1​
[/TD]
[TD]Item[/TD]
[TD]Value[/TD]
[TD][/TD]
[TD]Lookup[/TD]
[TD][/TD]
[TD]Count[/TD]
[/TR]
[TR]
[TD]
2​
[/TD]
[TD]A[/TD]
[TD]
23
[/TD]
[TD][/TD]
[TD]X[/TD]
[TD]E[/TD]
[TD]
2​
[/TD]
[/TR]
[TR]
[TD]
3​
[/TD]
[TD]X[/TD]
[TD]
34
[/TD]
[TD]E[/TD]
[TD][/TD]
[TD][/TD]
[TD]Value[/TD]
[/TR]
[TR]
[TD]
4​
[/TD]
[TD]C[/TD]
[TD]
24
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
34​
[/TD]
[/TR]
[TR]
[TD]
5​
[/TD]
[TD]B[/TD]
[TD]
64
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
34​
[/TD]
[/TR]
[TR]
[TD]
6​
[/TD]
[TD]X[/TD]
[TD]
89
[/TD]
[TD]E[/TD]
[TD][/TD]
[TD][/TD]
[TD]
34​
[/TD]
[/TR]
[TR]
[TD]
7​
[/TD]
[TD]X[/TD]
[TD]
82
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
34​
[/TD]
[/TR]
[TR]
[TD]
8​
[/TD]
[TD]A[/TD]
[TD]
73
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
9​
[/TD]
[TD]D[/TD]
[TD]
97
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
10​
[/TD]
[TD]C[/TD]
[TD]
97
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


In F2 just enter:

=COUNTIFS(A2:A10,D2,C2:C10,E2)

In F4 control+shift+enter, not just enter, and copy down:

=IF(ROWS($F4:F4)>$F$2,"",INDEX($B$2:$B$10,SMALL(IF($A$2:$A$10=$D$2,IF($C$2:$C$10=$E$2,ROW($B$2:$B$10)-ROW($B$2)+1)),ROWS($F4:F4))))

Thanks for the help .. Unfortunately the resulted "Value" In column F are not correct though.. There should be only 2 values, 34 & 89 as those are the only 2 that have X in column A and E in column C ?
 
Upvote 0
Thanks for the help .. Unfortunately the resulted "Value" In column F are not correct though.. There should be only 2 values, 34 & 89 as those are the only 2 that have X in column A and E in column C ?

My bad. ROWS($F4:F4) should have been ROWS($F$4:F4)...

To re-cap:

[Table="width:, class:grid"][tr][td]Row\Col[/td][td]
A​
[/td][td]
B​
[/td][td]
C​
[/td][td]
D​
[/td][td]
E​
[/td][td]
F​
[/td][/tr][tr][td]
1​
[/td][td]Item[/td][td]Value[/td][td][/td][td]Lookup[/td][td][/td][td]Count[/td][/tr]
[tr][td]
2​
[/td][td]A[/td][td]
23
[/td][td][/td][td]X[/td][td]E[/td][td]
2​
[/td][/tr]
[tr][td]
3​
[/td][td]X[/td][td]
34
[/td][td]E[/td][td][/td][td][/td][td]Value[/td][/tr]
[tr][td]
4​
[/td][td]C[/td][td]
24
[/td][td][/td][td][/td][td][/td][td]
34​
[/td][/tr]
[tr][td]
5​
[/td][td]B[/td][td]
64
[/td][td][/td][td][/td][td][/td][td]
89​
[/td][/tr]
[tr][td]
6​
[/td][td]X[/td][td]
89
[/td][td]E[/td][td][/td][td][/td][td][/td][/tr]
[tr][td]
7​
[/td][td]X[/td][td]
82
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td]
8​
[/td][td]A[/td][td]
73
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td]
9​
[/td][td]D[/td][td]
97
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td]
10​
[/td][td]C[/td][td]
97
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]


In F2 just enter:

=COUNTIFS(A2:A10,D2,C2:C10,E2)

This return a count of records that meet the conditions.

In F4 control+shift+enter, not just enter, and copy down:

=IF(ROWS($F$4:F4)>$F$2,"",INDEX($B$2:$B$10,SMALL(IF($A$2:$A$10=$D$2,IF($C$2:$C$10=$E$2,ROW($B$2:$B$10)-ROW($B$2)+1)),ROWS($F$4:F4))))

This lists the records that meet the conditions.
 
Upvote 0
My bad. ROWS($F4:F4) should have been ROWS($F$4:F4)...

To re-cap:

[TABLE="class: grid"]
<tbody>[TR]
[TD]Row\Col[/TD]
[TD]
A​
[/TD]
[TD]
B​
[/TD]
[TD]
C​
[/TD]
[TD]
D​
[/TD]
[TD]
E​
[/TD]
[TD]
F​
[/TD]
[/TR]
[TR]
[TD]
1​
[/TD]
[TD]Item[/TD]
[TD]Value[/TD]
[TD][/TD]
[TD]Lookup[/TD]
[TD][/TD]
[TD]Count[/TD]
[/TR]
[TR]
[TD]
2​
[/TD]
[TD]A[/TD]
[TD]
23
[/TD]
[TD][/TD]
[TD]X[/TD]
[TD]E[/TD]
[TD]
2​
[/TD]
[/TR]
[TR]
[TD]
3​
[/TD]
[TD]X[/TD]
[TD]
34
[/TD]
[TD]E[/TD]
[TD][/TD]
[TD][/TD]
[TD]Value[/TD]
[/TR]
[TR]
[TD]
4​
[/TD]
[TD]C[/TD]
[TD]
24
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
34​
[/TD]
[/TR]
[TR]
[TD]
5​
[/TD]
[TD]B[/TD]
[TD]
64
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
89​
[/TD]
[/TR]
[TR]
[TD]
6​
[/TD]
[TD]X[/TD]
[TD]
89
[/TD]
[TD]E[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
7​
[/TD]
[TD]X[/TD]
[TD]
82
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
8​
[/TD]
[TD]A[/TD]
[TD]
73
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
9​
[/TD]
[TD]D[/TD]
[TD]
97
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
10​
[/TD]
[TD]C[/TD]
[TD]
97
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


In F2 just enter:

=COUNTIFS(A2:A10,D2,C2:C10,E2)

This return a count of records that meet the conditions.

In F4 control+shift+enter, not just enter, and copy down:

=IF(ROWS($F$4:F4)>$F$2,"",INDEX($B$2:$B$10,SMALL(IF($A$2:$A$10=$D$2,IF($C$2:$C$10=$E$2,ROW($B$2:$B$10)-ROW($B$2)+1)),ROWS($F$4:F4))))

This lists the records that meet the conditions.


You the man, thank you so much! :biggrin:
 
Upvote 0

Forum statistics

Threads
1,224,894
Messages
6,181,618
Members
453,057
Latest member
LE102024

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