If there are only 2 options for Y2, Y2 = 1 or Y2 = 2, then don't make any changes to the formula.

Another way to write it would be:

=INDEX(CHOOSE(Y2,$AA$8:$AA$12,$AB$8:$AB$12),MATCH(Y8,$Y$8:$Y$12,0))