sur*_*man 2 excel vba excel-vba excel-formula
我有3列A,B,C,我需要合并3列,我已经应用了forumala =A1&","&B1&","&C1输出来自E列我需要输出为D列.
以下公式将达到您想要的结果:
=TEXTJOIN(",",TRUE,A1:C1)
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)