本帖最后由 tmplinshi 于 2024-3-17 21:33 编辑
- =LET(
- src, A1:B33,
- fruits, K1:K11,
- a, INDEX(src, , 1),
- b, INDEX(src, , 2),
- isFruit, ISNUMBER(MATCH(b, fruits, 0)),
- isPreFruit, VSTACK(0, DROP(isFruit, -1)),
- str, CONCAT(IF((a = "") * isFruit * isPreFruit, "、" & b, ";" & a & "," & b)),
- result1, TEXTSPLIT(REPLACE(str, 1, 1, ), ",", ";", , , ""),
-
- newA, INDEX(result1, , 1),
- newB, INDEX(result1, , 2),
- containsFruit, ISNUMBER(FIND("、", newB)) + COUNTIF(fruits, newB),
- newStr, CONCAT((";" & newA & "," & newB) & IF(containsFruit, ";," & newB, "")),
- TEXTSPLIT(REPLACE(newStr, 1, 1, ), ",", ";", , , "")
- )
复制代码
方法二:
- =LET(
- src, A1:B33,
- fruits, K1:K11,
- a, INDEX(src, , 1),
- b, INDEX(src, , 2),
- isFruit, ISNUMBER(MATCH(b, fruits, 0)),
- isPreFruit, VSTACK(0, DROP(isFruit, -1)),
- str, CONCAT(IF((a = "") * isFruit * isPreFruit, "、" & b, ";" & a & "," & b)),
- result1, TEXTSPLIT(REPLACE(str, 1, 1, ), ",", ";", , , ""),
-
- newB, INDEX(result1, , 2),
- newCols, IF(MATCH(TEXTBEFORE(newB,"、",,,,newB),fruits,0), HSTACK(TEXT(newB,";;;"), newB)),
- WRAPROWS(TOROW(HSTACK(result1, newCols), 2), 2)
- )
复制代码 |