1

我正在尝试用分号分隔符连接其他每一列中的单元格。我拥有并且基本上有效的公式是:

=IF(SUBSTITUTE(TRIM(H2&" "&J2&" "&L2&" "&N2&" "&P2&" "&R2&" "&T2&" "&V2&" "&X2&" "&Z2)," ","; ")="","",SUBSTITUTE(TRIM(H2&" "&J2&" "&L2&" "&N2&" "&P2&" "&R2&" "&T2&" "&V2&" "&X2&" "&Z2)," ","; "))

但是我遇到的问题是一些单元格包含带空格的文本,并且公式将分隔符放在合法空格的位置。我该如何纠正?

提前致谢!

4

2 回答 2

4

您正在调用SUBSTITUTE的空格字符不仅是您的临时分隔符,而且还是连接字符串中的模式。

肮脏而快速的解决方案是使用不会出现在H2, L2, N2...单元格中的临时分隔符模式。在这里,我选择了,###但任何其他模式都可以解决问题。

=IF(SUBSTITUTE(TRIM(H2&"###"&J2&"###"&L2&"###"&N2&"###"&P2&"###"&R2&"###"&T2&"###"&V2&"###"&X2&"###"&Z2),"###","; ")="","",SUBSTITUTE(TRIM(H2&"###"&J2&"###"&L2&"###"&N2&"###"&P2&"###"&R2&"###"&T2&"###"&V2&"###"&X2&"###"&Z2),"###","; "))
于 2012-05-08T13:50:52.763 回答
1

这行得通吗?

=IF(COUNTA(H2,J2,L2,N2,P2,R2,T2,V2,X2,Z2),H2&";"&J2&";"&L2&";"&N2&";"&P2&";"&R2&";"&T2&";"&V2&";"&X2&";"&Z2,"")

或者当你有空格时只显示一次分隔符也许试试这个版本

=SUBSTITUTE(IF(H2="","",";"&H2)&IF(J2="","",";"&J2)&IF(L2="","",";"&L2)&IF(N2="","",";"&N2)&IF(P2="","",";"&P2)&IF(R2="","",";"&R2)&IF(T2="","",";"&T2)&IF(V2="","",";"&V2)&IF(X2="","",";"&X2)&IF(Z2="","",";"&Z2),";","",1)

于 2012-05-08T19:51:19.757 回答