答案 0 :(得分:5)
以下公式将达到您想要的结果:
=TEXTJOIN(",",TRUE,A1:C1)
Textjoin的作用类似于连接,但可以使用定界符作为参数,它还使您能够忽略空白单元格,第一个参数是定界符,第二个是忽略空白的标志,第三个是用于范围的标志。
正如评论确实提到的那样,TEXTJOIN仅适用于Office 365订阅者,一种可能的替代方法是按以下方式构建您的UDF,这将允许您使用上面的公式而无需Office 365订阅:
Function TEXTJOIN(delimiter As String, ignore_empty As Boolean, rng As Range) As String
Dim compiled As String
For Each cell In rng
If ignore_empty And IsEmpty(cell.Value) Then
'nothing
Else
compiled = compiled + IIf(compiled = "", "", delimiter) + CStr(cell.Value)
End If
Next
TEXTJOIN = compiled
End Function
答案 1 :(得分:3)
将此公式输入E1
:
=CONCATENATE(A1, IF(AND(B1<>"", A1<>""), ",", ""), B1,
IF(AND(OR(A1<>"", B1<>""), C1<>""), ",", ""), C1)
使用TEXTJOIN
可能是一种更清洁的选择,但仅在更新的Excel版本中可用。
答案 2 :(得分:1)
答案 3 :(得分:1)
'Put this code in module and use formula concmulti and select the range
Function concmulti(slt As Range) As String
Dim str As String
Dim cell As Range
For Each cell In slt
str = str & cell.Value & ", "
Next cell
concmulti = str
End Function