Excel 功能:如何连接忽略逗号和 NULL 值的字符串
Excel Function: How do I concatenate String ignoring comma and NULL values
如何在忽略 A1 到 F1 不同单元格中的逗号和 NULL 值的情况下连接下面的字符串。
NULL NULL Welcome NULL NaiSen NULL
我的最终结果应该是:欢迎您,奈森
我尝试使用下面的函数但得到了#VALUE!
=CONCATENATE(IF(SEARCH("NULL",A1:F1),"",""))
试试下面的想法:
=CONCATENATE(IF(A1="null","",CONCATENATE(SUBSTITUTE(A1,",",""),",")),
IF(B1="null","",CONCATENATE(SUBSTITUTE(B1,",",""),",")),
IF(C1="null","",CONCATENATE(SUBSTITUTE(C1,",",""),",")),
IF(D1="null","",CONCATENATE(SUBSTITUTE(D1,",",""),",")),
IF(E1="null","",CONCATENATE(SUBSTITUTE(E1,",",""),",")),
IF(F1="null","",SUBSTITUTE(F1,",","")))
您可以像这样使用用户定义的 VBA 函数
Function concatFunc(v As Range) As String
Application.Volatile True
Dim c
Dim s As String
For Each c In v
If IsError(c) = False And CStr(c) <> "," Then
s = s & CStr(c)
End If
Next
concatFunc = s
End Function
像这样在 VBA 中插入代码:
Alt-F11,插入模块,粘贴代码
然后调用工作表中的函数,如下例所示:
=concatFunc(A1:F1)
然后它像任何其他内置 Excel 函数一样工作。
如何在忽略 A1 到 F1 不同单元格中的逗号和 NULL 值的情况下连接下面的字符串。
NULL NULL Welcome NULL NaiSen NULL
我的最终结果应该是:欢迎您,奈森
我尝试使用下面的函数但得到了#VALUE!
=CONCATENATE(IF(SEARCH("NULL",A1:F1),"",""))
试试下面的想法:
=CONCATENATE(IF(A1="null","",CONCATENATE(SUBSTITUTE(A1,",",""),",")),
IF(B1="null","",CONCATENATE(SUBSTITUTE(B1,",",""),",")),
IF(C1="null","",CONCATENATE(SUBSTITUTE(C1,",",""),",")),
IF(D1="null","",CONCATENATE(SUBSTITUTE(D1,",",""),",")),
IF(E1="null","",CONCATENATE(SUBSTITUTE(E1,",",""),",")),
IF(F1="null","",SUBSTITUTE(F1,",","")))
您可以像这样使用用户定义的 VBA 函数
Function concatFunc(v As Range) As String
Application.Volatile True
Dim c
Dim s As String
For Each c In v
If IsError(c) = False And CStr(c) <> "," Then
s = s & CStr(c)
End If
Next
concatFunc = s
End Function
像这样在 VBA 中插入代码: Alt-F11,插入模块,粘贴代码
然后调用工作表中的函数,如下例所示: =concatFunc(A1:F1)
然后它像任何其他内置 Excel 函数一样工作。