Search code examples
excelindexingmatchformula

If cell equals condition, find next value in a column and return it's adjacent value


I need some help with an excel formula. In E2, I need to do a formula like this:

=if(A2=1,find-in-Column-C-starting-from-C2,where-next-"Fruit"-is, and-return-the-adjacent-cell-in-column-B, else return blank)

enter image description here

E2 should return B3

E4 should return B5

E6 should return B11

E12 should return B12

E13 should return B17

and so on.


Solution

  • You can try the following for an array solution that spills the entire result. I am assuming there is no Excel version constraints as per the tags listed in the question.

    =LET(A,A1:A16, B,B1:B16, C,C1:C16, seq,SEQUENCE(ROWS(A)), MAP(A,seq, 
     LAMBDA(x,s,IF(x=1,@FILTER(B,(seq>=s)*(C="Fruit"),""),""))))
    

    Here is the output output

    We use @-operator to get the first element of the FILTER result. The third FILTER input argument is used to prevent any error in case the output is empty.