There are many approaches but I personally prefer the use of helper rows/columns/cells and named ranges.
In my demonstration I used two class attendant schedule in two different year from January to June as shown below (they are sitting in Column C to M in my example):

As shown above, I have added two helper rows on top of each schedule. The first helper row is used to find out if there is 2 or more vacancies in each month, if so returns TRUE
. I have given the name check.2019.class.1 and check.2021.class.5 for each of them.
The second helper row is simply showing the range name of each month such as jan_2019_class.1
, feb_2019_class.2
etc. I have given the name NameRng.2019.class.1 and NameRng.2021.class.5 for each of them.
On the TEST
sheet I have the following set up:

where the look up value in cell C3
is actually returned by a formula so it can be "dynamically" changed by the user. Please note in the following formula I used a name ClassNo which is essentially the value from cell B3
.
=B2&"_"&B1&"_class."&ClassNo
I have also named cell C3
as Start_MthYrClass which will be used in my following formula.
The formula for looking up the first available month in 2019 if the start month is jan_2019_class.1
is:
=INDEX(NameRng.2019.class.1,MATCH(1,(TRANSPOSE(ROW($1:$11))>=MATCH(Start_MthYrClass,NameRng.2019.class.1,0))*Check.2019.class.1,0))
Please note it is an array formula so you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar otherwise they will not function correctly.

The logic is to first "filter" the range NameRng.2019.class.1 using this formula =TRANSPOSE(ROW($1:$11))>=MATCH(Start_MthYrClass,NameRng.2019.class.1,0)
, in which ROW($1:$11)
represents {1;2;3;4;5;6;7;8;9;10;11}
and TRANSPOSE will turn it into {1,2,3,4,5,6,7,8,9,10,11}
. This range of numbers represents the column index in that specific range which is Column C to M (in your case it would be ROW($1:$56)
as your data is in Column C to BF). Then I use MATCH to return the start column index of the look up month jan_2019_class.1
, and it should return 1
as this month starts in the 1st place/column in the range NameRng.2019.class.1. So this is what I am actually comparing: {1,2,3,4,5,6,7,8,9,10,11}>=1
, and it will return {TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE}
.
Then I multiply the above result with range Check.2019.class.1 which is essentially {FALSE,0,FALSE,0,TRUE,0,FALSE,0,TRUE,0,TRUE}
. Then I will get {0,0,0,0,1,0,0,0,1,0,1}
. FYI in Excel TRUE=1
and FALSE=0
, so TRUE x FALSE = 0
while TRUE x TRUE = 1
.
Lastly, I use MATCH to find out the position of the first 1
in the above result which is the 5th place/column, and then use INDEX to return the corresponding value from range NameRng.2019.class.1 which is mar_2019_class.1
.
Here is a more universal formula which allows you enter it in the first cell C6
and drag it down to apply across board, if you have given names to the relevant cells and ranges in the same way as what I have demonstrated.
=IFERROR(INDEX(INDIRECT("NameRng."&B6&".class."&ClassNo),MATCH(1,(TRANSPOSE(ROW($1:$11))>=MATCH(Start_MthYrClass,INDIRECT("NameRng."&B6&".class."&ClassNo),0))*INDIRECT("Check."&B6&".class."&ClassNo),0)),"")
It is also an array formula so you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar.
It is essentially the same formula as the first one but I have added IFERROR to return a blank cell if there is no match, and I used INDIRECT to refer to the named ranges dynamically based on the year and class number chosen.
Now, if I change the look up criteria to mar_2021_class.5
, here is an updated result:

Let me know if you have any questions. Cheers :)