you will have to change the $A$2:$A$20 range two times to the wished range given by INDIRECT.
=INDEX($A$2:$A$20, MATCH(0, COUNTIF($B$1:B1, $A$2:$A$20), 0))
Let's say you have a third column, C with a header row 1 and data from row 2.
This function will work only if the data in column C is sorted.
You type your filter criteria in cell $E$1.
- using MATCH to find the first occurrence of the filter criteria:
- MATCH($E$1,$C$1:$C$20,0)
- using COUNTIF to fing out how many rows have this criteria:
COUNTIF($C$1:$C$20,$E$1) - the range will start in the row given by MATCH($E$1,$C$1:$C$20,0)
and end in the row given by (MATCH($E$1,$C$1:$C$20,0)+COUNTIF($C$1:$C$20,$E$1)-1) - now add the letter of the data column to the range like "A"&
- your range starting cell will be INDIRECT("A"&MATCH($E$1,$C$1:$C$20,0))
your range ending cell will be INDIRECT("A"&(MATCH($E$1,$C$1:$C$20,0)+COUNTIF($C$1:$C$20,$E$1)-1)) - the string you will paste in place of $A$2:$A$20 will be INDIRECT("A"&MATCH($E$1,$C$1:$C$20,0)):INDIRECT("A"&(MATCH($E$1,$C$1:$C$20,0)+COUNTIF($C$1:$C$20,$E$1)-1))