try:
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(A2:G),
"select "&TEXTJOIN(",", 1, IF(LEN(A2:A),
"min(Col"&ROW(A2:A)-ROW(A2)+1&")", ))&"")),
"select Col2"))
и заголовки:
=ARRAYFORMULA(IFNA(VLOOKUP(I2:I, SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(B2:D="",,"♠"&B2:D&"♦"&B1:D1))
,,99^99)),,99^99), "♠")), "♦"), 2, 0)))