Excel – How to display only data that meets certain criteria in Excel

microsoft excelmicrosoft-excel-2010

I have a list of names, with one column further on with numerical data within, for argument's sake like shown below:

Dave    1
Bob     2
Frank   1
Dennis  3

I would like to have another table on a different sheet that selects and displays the names depending on the number next to the name.

So for example the column 1 would have the names Dave and Frank listed below

Is this possible?

Best Answer

You can do this with an array formula. Do the following:

  1. Set up your table on a new sheet. Create column headers 1, 2, 3, etc.
  2. Under header 1 (in A2), type the following.

    =IFERROR(INDEX(Sheet1!$A$1:$A$5,SMALL(IF(Sheet1!$B$1:$B$5=Sheet2!A$1,ROW(Sheet1!$B$1:$B$5)),ROWS(B$2:B2))),"")

    where Sheet1 is the sheet with the original data, A1:A5 is the list of names in the original data (including column header), and B1:B5 is the list of numbers in the original data (including column header).

  3. After typing the formula, place the cursor in the formula bar and press Ctrl+Shift+Enter. This will enter the formula as an array formula. The formula will show up in the formula bar surrounded by curly braces.

  4. Now fill this formula over to all the columns in your new table. Then fill the formula down as far as you need to get all the names to appear.

Explanation of formula:

The SMALL(IF(Sheet1!$B$1:$B$5=Sheet2!A$1,ROW(Sheet1!$B$1:$B$5)),ROWS(B$2:B2)) part of the formula looks through the original data for records that match the number specified by the column header. If a match is found, the row number of each match is returned as this is filled down.

The INDEX(Sheet1!$A$1:$A$5, ...) part of the formula returns the name from the row number found.

The IFERROR(..., "") part checks what is returned by INDEX for an error. If an error is found, the formula returns nothing.

Related Question