如何在列中的所有值中添加单引号和逗号? [英] How to add single quote and comma to all values in a column?
本文介绍了如何在列中的所有值中添加单引号和逗号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一列主机
具有以下值:
server1.abc.com
server2.abc.com
server3
现在,我将这些值中的每一个值作为单引号并以逗号分隔。输出应如下所示:
Now, I want each of these values to be single quotes and separated by comma. The output should be like as below:
'server1.abc.com','server2.abc.com','server3'
请让我知道如何使用Excel实现这一点。
Please let me know how this can be achieved using Excel.
到目前为止,我可以使用,
使用以下代码分隔值:
So far I am able to separate values using ,
with following code:
Public Function MergeME(r As Range) As String
MergeME = Join(Application.Transpose(r.Value), ",")
End Function
如何在每个单元格的值中添加双引号?
How can I add double quotes around values in each cell??
推荐答案
您原来的UDF很近。你只需要加入','
而不是,
然后放置'
在输出字符串的开头和结尾
Your original UDF was close. You just need to join with ','
rather than ,
and then place '
at the start and end of your output string
Public Function MergeME(r As Range) As String
MergeME = "'" & Join(Application.Transpose(r.Value), "','") & "'"
End Function
根据需要输出字符串:
'server1.abc.com','server2.abc.com','server3'
这篇关于如何在列中的所有值中添加单引号和逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文