excel

Search value in Column specified in another cell


in this table I have:

enter image description here

Column "A": number of operations in the same day

Column "B": Date

Column "C:F": results

Column "G": formula that search if there's a previous positive result in same day

Column "J": manual column input

In the column "G" I have to manually change the column to search for, column "C"/"D"/"E" or"F"

=IF(AND(A2>1,C1=1),"ok","")

I want to be able to reference this formula to a cell so I just change cell "J1" with the column to search without modifying the formula.

For example: in cell "J1" I put "X", so in column "G" will be searching results in "D:D" with title "X"


Solution

  • I would use this formula to do what you need with the control you have. It checks the first column that it's over 1, then it does an index match to search the range for but matches the column so it knows which to search. The row()-1 is because the range starts one below the header, so you may need to adjust this if necessary.

    =IF(AND($A2>1, INDEX($C$2:$F$5,ROW()-1,MATCH($J$1,$C$1:$F$1,0))=1),"ok","")

    enter image description here