如何在一行中搜索单元格值然后输出 header?

How to search a row for cell value(s) then output the header?

我是新来的,正在尝试自动化。我有一个工作名册,希望它每天输出值班人员。理想情况下。它会检查今天的日期,然后每天在相应的 table 行中搜索相关人员。

Screenshot

电子表格:here

期望的输出:

today's date,上午班次为 Person 1 (duty) Person 2,下午班次为 Person 3

当前公式:

="On "&textjoin("",TRUE,B7)&": AM shifts are "
&OFFSET(INDEX(A3:E3,MATCH("AM Duty",A3:E3,0)),1-row(vlookup(today(),A1:E5,2,0)),0)&" (duty) "
&OFFSET(INDEX(A3:E3,MATCH("AM Reg",A3:E3,0)),1-row(vlookup(today(),A1:E5,2,0)),0)
&", PM shifts are "
&OFFSET(INDEX(A3:E3,MATCH("PM Reg",A3:E3,0)),1-row(vlookup(today(),A1:E5,2,0)),0)

公式的一些问题:

  1. 行在列表中向下移动时需要根据今天的日期进行调整,目前它是硬编码的A3:E3
  2. 不确定如何捕获每行中重复的 AM Reg

不确定我是否把这里的事情复杂化了,并且愿意接受更好的解决方案。提前致谢!

尝试:

=INDEX(TEXT(TODAY(), "On dd mmmm yy: A\M \s\hift\s ar\e ")&
 TEXTJOIN(", ", 1, IF(REGEXMATCH(VLOOKUP(TODAY(), A2:E5, {2,3,4,5}, ), "AM Duty"), B1:E1&" (duty), ", ))&
 TEXTJOIN(", ", 1, IF(REGEXMATCH(VLOOKUP(TODAY(), A2:E5, {2,3,4,5}, ), "AM Reg"),  B1:E1, ))&" and PM shifts are "&
 TEXTJOIN(", ", 1, IF(REGEXMATCH(VLOOKUP(TODAY(), A2:E5, {2,3,4,5}, ), "PM Duty"), B1:E1&" (duty), ", ))&
 TEXTJOIN(", ", 1, IF(REGEXMATCH(VLOOKUP(TODAY(), A2:E5, {2,3,4,5}, ), "PM Reg"),  B1:E1, )))