我有一个带有a,b,c等标签的列。单元格中的标签是唯一的,用“,”(逗号和空格)分隔,但没有排序。我想要一个数组公式来返回每个单元格中带有排序标签的列。 例如 在A1:A5
c, a
b, a, d
a, c
c
c, b, a
我希望B1中的数组公式在B1:B5中返回结果
a, c
a, b, d
a, c
c
a, b, c
在单元格中排序后,我可以看出标签“c,a”与标签“a,c”相同。 我的公式只返回一个单元格
=ARRAYFORMULA(JOIN(", ",SORT(TRANSPOSE(SPLIT(A1:A5,", ",FALSE)))))
答案 0 :(得分:1)
ARRAYFORMULA:
=ArrayFormula(TRIM(TRANSPOSE(SPLIT(CONCATENATE(REPT(TRANSPOSE(QUERY(SORT({TRANSPOSE(SPLIT(JOIN(", ",ArrayFormula(REGEXREPLACE(A1:A5,"\w+",TEXT(row(A1:A5),"0")))),", ")),TRANSPOSE(SPLIT(JOIN(", ",A1:A5),", "))},1,1,2,1),"select Col2",0)&", "),ROW(A1:A5)=SPLIT(JOIN(", ",ArrayFormula(REGEXREPLACE(A1:A5,"\w+",TEXT(row(A1:A5),"0")))),", "))&REPT(" "&CHAR(9),TRANSPOSE(row(OFFSET(A1,,,COUNTA(SPLIT(JOIN(", ",A1:A5),", "))))-row($A$1)+1)=COUNTA(SPLIT(JOIN(", ",A1:A5),", ")))),", "&CHAR(9),0))))
我使用this tip来解决任务。
<强>更新强>
通过一些编辑,此公式还可以处理逗号分隔的短语:
=ArrayFormula(TRIM(TRANSPOSE(SPLIT(CONCATENATE(REPT(TRANSPOSE(QUERY(SORT({TRANSPOSE(SPLIT(JOIN(",",ArrayFormula(REGEXREPLACE(A1:A5,"[^,]+",TEXT(row(A1:A5),"0")))),",",0)),TRANSPOSE(SPLIT(JOIN(", ",A1:A5),", ",0))},1,1,2,1),"select Col2",0)&", "),ROW(A1:A5)=SPLIT(JOIN(",",ArrayFormula(REGEXREPLACE(A1:A5,"[^,]+",TEXT(row(A1:A5),"0")))),",",0))&REPT(" "&CHAR(9),TRANSPOSE(row(OFFSET(A1,,,COUNTA(SPLIT(JOIN(", ",A1:A5),", ",0))))-row($A$1)+1)=COUNTA(SPLIT(JOIN(", ",A1:A5),", ",0)))),", "&CHAR(9),0))))
file sample。关键是REGEXREPLACE
公式的一部分:"[^,]+"
答案 1 :(得分:0)
Arrayformula和split不能在多行上运行。我能想到的最好的就是用脚本填写公式。你可以在onOpen或onEdit上做。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {Configuration.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class SomeTests {
...