将匹配项目always是连续的吗?看起来是这样,因为您在公式逻辑中将每个项目单元格与其上方的单元格进行比较。这打破了电子表格标准化的[不成文?]规则;价值观'地址它们本身通常不应被视为数据。
如果您决心这样做,您是否考虑过明确使用位置作为数据源?例子:
=ARRAYFORMULA(IFS(
NOT(LEN(A3:A40)),,
ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0)<=VLOOKUP(VLOOKUP(A3:A40,Items!$A$2:$D,2,false),DataPerColor!$A$2:$B,2,false),ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0),
true,
))
就像你的公式一样,英文的全部内容是:
for each row,
if there's no Item, don't output any ItemData,
if the number that belongs in this cell¹ is less than or equal to the lookup, print it,
otherwise, don't output any ItemData
但是,“属于该单元格的数字”是什么?我们如何在不使用 B 列的情况下计算它呢?我滥用物品的位置来获取它。往下看 B 行,出现的每个数字只是:
this row's number, minus
the row where items start [always 3], minus
the row number [in just the Item rows] of the first row containing this row's Item
Using 倒数第二个项目C举个例子:第一个 ItemC 是第 16 个项目列表,我们正在查找的项目...“倒数第二个 ItemC”位于工作表的第 21 行。 21-3-16 = 2 …你想要的数字。
如果您能接受,它是单一配方,并且可以根据您的规格发挥作用。