0
votes

Now I have an excel file with 2 sheets, I need to pull some data from sheet1 to sheet2, based on a single criterion - Text in Column A from sheet1 contains certain text string from A2 from sheet2. In the meantime, I also have to pull data from other columns from those rows where the text string is found. However, Vlookup only returns the first instance. Since the file is confidential, I created a moackup for this.

Sheet1

Classes Taken   Name    Gender  Age

Math,Physics,Chemistry, Literature  Joseph  Male    16

Chinese, History, Philosophy, Politics  Alice   Female  17

Philosophy, Math, Physics   Erica   Female  16

Chinese, Biology, Statistics    Evan    Male    18

Sheet2

Philosophy  (Lookup)

Name    Gender  Age

What if I want the information of people who have taken philosophy class displayed in sheet2.

Thank you!!

2
If you need all instances, you would need VBA. Formula is not sufficient. - findwindow
I don't really know about VBA, is there any code that could be apply on this case directly? - Joseph Lin
Consider using a pivot table. - Doug Glancy
Then mock up some data that is in the same format and show what your expected outcome would be with that mock data. - Scott Craner
Is "Math, Physics, Chemisty, Literature" all in the same cell, in column A? - BruceWayne

2 Answers

0
votes

NON-ARRAY SOLUTION

Sheet1
- Enter table data on Sheet1 as shown here:
Sheet1 Thumbnail Image

Sheet2
- Cell A1 contains the lookup value: Philosophy.
- Cells A2:C2 contain the header row data: Name Gender Age
- In cell A3, insert this formula:
=INDEX(Sheet1!$A2:$D2,MATCH("*"&$A$1&"*",Sheet1!$A2:$A2,0),MATCH(A$2,Sheet1!$A$1:$D$1,0))
- Press ENTER.
- Copy across to C3, then down to C6 to get the result shown here:
Sheet2 Thumbnail Image

0
votes

ARRAY SOLUTION

Sheet1
- Enter table data on Sheet1 as shown here:
Sheet1 Thumbnail Image

Sheet2
- Cell A1 contains the lookup value: Philosophy.
- Cells A2:C2 contain the header row data: Name Gender Age
- In cell A3, insert this formula:
=IFERROR(INDEX(Sheet1!B$2:B$5,SMALL(IF(ISNUMBER(SEARCH($A$1,Sheet1!$A$2:$A$5)),ROW(Sheet1!B$2:B$5)-ROW(Sheet1!B$2)+1),ROWS(Sheet1!$1:1))),"")
- Press CTRL+SHIFT+ENTER.
- Copy across to C3, then down to C6 to get the result shown here:
Sheet2 Thumbnail Image

Please Note
- This formula contains the IFERROR function, which will only work in Excel for PC 2007 or newer. It will also work in Excel for Mac 2011 or newer (according to Microsoft's documentation).
- This formula is also an ARRAY, which may slow things down if you're working with a large dataset.
- Each time you edit this formula, reconfirm by pressing CTRL+SHIFT+ENTER.