我有一列包含多个单词字符串。像这样:
+---+-------------------------------+--------------+-------------------------------+--------------+-------------------------------+-------------------------------+
| | A | B | C | D | E | F |
+---+-------------------------------+--------------+-------------------------------+--------------+-------------------------------+-------------------------------+
| 1 | Early Summer Lawn Application | Service Call | Early Summer Lawn Application | Grub Control | Early Summer Lawn Application | Early Summer Lawn Application |
+---+-------------------------------+--------------+-------------------------------+--------------+-------------------------------+-------------------------------+
我的问题是如何在列中的每个单词之后插入逗号,以结尾:
+---+-------------------------------+--------------+-------------------------------+--------------+-------------------------------+-------------------------------+
| | A | B | C | D | E | F |
+---+-------------------------------+--------------+-------------------------------+--------------+-------------------------------+-------------------------------+
| 1 | Early,Summer,Lawn,Application | Service,Call | Early,Summer,Lawn,Application | Grub,Control | Early,Summer,Lawn,Application | Early Summer Lawn Application |
+---+-------------------------------+--------------+-------------------------------+--------------+-------------------------------+-------------------------------+
可以丢失单词之间的空格,如果结果在不同的列中也可以,但我只是不知道如何插入逗号。
最佳答案
这里不是简单的替换工作吗?
=replace(A1," ", ",")
用逗号代替空格。另一个功能是
=substitute(A1, " ", ",")
也可以使用,但替代项可能会派上用场。它指定要替换的事件。例如,如果您只想用逗号替换第一个空格,而其他空格保持原样,则请尝试以下操作:
=substitute(A1, " ", ",", 1)
底线,如果您知道要替换的位置(位置),请使用replace;如果您知道要替换的内容(内容),请使用replace。正如您所发现的,任何一种方法都可以解决一小类问题。
关于excel - Excel VBA-如何在列中的每个单词后插入逗号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31076555/