See if this is what you had in mind.
Sheet1
*
| A
| B
| C
| D
| E
| F
|
*
| | | | | | |
*
| | | | | | |
*
| *
| *
| | | | |
*
| *
| *
| | | | |
*
| *
| *
| | | | |
*
| *
| *
| *
| | | |
*
| *
| *
| *
| | | |
*
| *
| *
| *
| | | |
*
| *
| *
| *
| | | |
*
| *
| *
| *
| | | |
<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.