假设某个单元格中的文本看起来像
Write
如何仅从开头和结尾删除分号。结果应该是
;ABCD;EFGH
;;ABCD;EFGH;
答案 0 :(得分:3)
我确定有更好的方法可以做到这一点,但它确实有效!
=SplitSemiColon(A1)
将代码放在一个新模块中并使用工作表上的函数(例如):
data
答案 1 :(得分:1)
如果没有空格,另一种选择可以是将它们转换为空格,修剪和转换回来:
=Substitute(Trim(Substitute(A1,";"," "))," ",";")
TRIM
删除了额外的空格,因此上述内容会将;A;;;B;
变为A;B
,但VBA Trim
不会:
[A1] = Replace(Trim(Replace([A1],";"," "))," ",";") ' ";A;;;B;" into "A;;;B"
如果有空格,可以用不同的字符替换它们,但它太乱了:
=Substitute(Substitute(Trim(Substitute(Substitute(A1," ","_"),";"," "))," ",";"),"_"," ")