我目前正在使用以下代码:
=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(C28," ","^")&" "&SUBSTITUTE(C29," ","^")&" "&SUBSTITUTE(C30," ","^"))," ", ", "),"^"," ")
实现结果:文字,文字,文字
然而,我正在努力改变代码以获得结果,如果只有2个单元格有数据,那么它应该是文本&文本。如果3个单元格有数据,则应该是文本,文本和文本。文本。
任何人都可以帮我吗?
答案 0 :(得分:0)
您是否尝试使用CONCATENATE代替&“”&?
=SUBSTITUTE(SUBSTITUTE(CONCATENATE(TRIM(SUBSTITUTE(C28," ","^"))," ",TRIM(SUBSTITUTE(C29," ","^"))," ",TRIM(SUBSTITUTE(C30," ","^")))," ",", "),"^"," ")
答案 1 :(得分:0)
=IFERROR(REPLACE(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(C28," ","^")&" "&SUBSTITUTE(C29," ","^")&" "&SUBSTITUTE(C30," ","^"))," ", ", "),"^"," "),MAX(IFERROR(FIND(",",SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(C28," ","^")&" "&SUBSTITUTE(C29," ","^")&" "&SUBSTITUTE(C30," ","^"))," ", ", "),"^"," "),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(C28," ","^")&" "&SUBSTITUTE(C29," ","^")&" "&SUBSTITUTE(C30," ","^"))," ", ", "),"^"," "))))),0)),1," &"),SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(C28," ","^")&" "&SUBSTITUTE(C29," ","^")&" "&SUBSTITUTE(C30," ","^"))," ", ", "),"^"," "))
嘴巴满了但是这样做了......这是一个数组公式,用 Ctrl + Shift + 确认公式仍然在公式栏中输入。
答案 2 :(得分:0)
在xl2016 / Office 365中试用,
adParamOutput
如果您没有TEXTJOIN功能,可以在TEXTJOIN for xl2013 with criteria找到一个好的替代UDF。
答案 3 :(得分:0)
作为一种适用于大多数Excel版本的冗长方法,请尝试以下方法:
=IF(COUNTA(C28:C30)=3,TRIM(C28) & ", " & TRIM(C29) & ", " & TRIM(C29), IF(COUNTA(C28:C30)<2, TRIM(C28 & C29 & C30), IF(COUNTA(C28:C29)=2,TRIM(C28) & " & " & TRIM(C29), IF(COUNTA(C29:C30)=2,TRIM(C28) & " & " & TRIM(C29),TRIM(C28) & " & " & TRIM(C29)))))
=IF(COUNTA(C28:C30)=3,TRIM(C28) & ", " & TRIM(C29) & ", " & TRIM(C29)
如果我们有3个项目,请将它们加在一起,并在它们之间加上", "
IF(COUNTA(C28:C30)<2, TRIM(C28 & C29 & C30)
对于0或1个项目,将所有内容连接在一起以显示任何内容或单个项目
IF(COUNTA(C28:C29)=2,TRIM(C28) & " & " & TRIM(C29)
如果我们只有第一个和第二个项目,请将它们与项目之间的" & "
一起加入
之间
IF(COUNTA(C29:C30)=2,TRIM(C28) & " & " & TRIM(C29),TRIM(C28) & " & " & TRIM(C29))
如果我们只有第二个和第三个项目,请将它们与" & "
一起加入 否则,请加入第一个和第三个项目,其中" & "
介于
)))
关闭所有IF
s
=IF(COUNTA(C28:C30)=2, TEXTJOIN(" & ", true, c28:c30), TEXTJOIN(", ", true, c28:c30))
(如果只有2个项目,请跳过空白并使用" & "
加入,否则跳过空白并加入", "
。这也会处理任意长度的列表,而不仅仅是3个项目)< / p>