Array - search for value, returning neighbouring cell values with no gaps

dslhs

New Member
Joined
Apr 4, 2022
Messages
44
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I needed a similar array formula in the past and was helped hugely by this forum. But I can't replicate for a different context.

I'm looking for an array formula that will allow me to search for a value (in a table in a different sheet), and then return all the neighbouring cell values to the matches. Essentially, I want to be able to enter a class name in one sheet and return all the students in the class (taken from a list of students and their classes in a different sheet). I'd like the array to return the results with no gaps.

Here is the first sheet with the student class/course data:

Class List Excel.xlsx
D
14
Class List


I've obviously anonymised it, but the real data goes down to row 4293

Here is the second sheet. I'd like to put the search value in cell B1 and return the results A6 downwards.

Class List Excel.xlsx
A
6
Class Plan


I've got VLOOKUPS setup for the second sheet that will return key info about the students, but that all works. I would just like to find a way of getting the student names to appear based on what class is in B2.

(Later, I might look at creating a list in B2 with data validation so staff can just select from the list, but I don't believe that will matter for this array as it will just create the search value in B2, right?

Thank you!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
@dslhs
You need to select the actual range in your worksheet that you want to show before clicking 'Mini Sheet'
 
Upvote 0
:ROFLMAO:my bad!

First sheet:

Class List Excel.xlsx
AB
1NameCourse/Class Name
2Student AEnglish A
3Student AMaths B
4Student AScience A
5Student AFrench C
6Student AHistory A
7Student ARE C
8Student BEnglish A
9Student BMaths A
10Student BScience B
11Student BFrench B
12Student BHistory A
13Student BRE C
14Student CEnglish B
15Student CMaths A
16Student CScience B
17Student CFrench B
18Student CHistory A
19Student CRE A
Class List


Second sheet:

Class List Excel.xlsx
AB
1Class:English A
2
3
4
5Student List:
6
7
Class Plan
 
Upvote 0
Here is one way to do it. You didn't say, so I assume you first sheet was named Sheet1. Put this array-entered** formula on your second sheet in cell B5 and copy down for as many cells as you have students...
Excel Formula:
=IFERROR(INDEX(Sheet1!A:A,SMALL(IF(Sheet1!B$2:B$19=$B$1,ROW(Sheet1!B$2:B$19)),ROWS(B$5:B5))),"")

**Commit this formula using CTRL+SHIFT+ENTER and not Enter by itself
 
Upvote 0
You didn't say, so I assume you first sheet was named Sheet1.
;)
1654477443789.png


@dslhs
Thanks for the 'better' XL2BB samples. (y)
If you would prefer to avoid the C+S+E formula confirmation, here is an alternative that does not require it.

dslhs.xlsm
AB
1Class:English A
2
3
4
5Student List:Student A
6Student B
7 
8 
Class Plan
Cell Formulas
RangeFormula
B5:B8B5=IFERROR(INDEX('Class List'!A:A,AGGREGATE(15,6,ROW('Class List'!A$2:A$5000)/('Class List'!B$2:B$5000=B$1),ROWS(B$5:B5))),"")
 
Upvote 0
Solution
You're welcome. Glad we could help. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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