为什么修剪不适用于VBA?
for i = 3 to 2000
activesheet.cells(i,"C").value = trim(Activesheet.cells(i,"C").value)
next i
Run Code Online (Sandbox Code Playgroud)
无论我如何尝试它无法删除文本之间的空格
hiii how ' even after trying trim the o/p is still these
hiii how
Run Code Online (Sandbox Code Playgroud)
我做装饰有什么不对吗?我只需要删除多余的空间,所以我发现修剪它做但它不能正常工作ltrim和rtrim工作正常
aev*_*nko 26
该VBA Trim函数是比Excel的不同.请改用Excel的Application.WorksheetFunction.Trim功能.
Excel修剪将删除除单词之间的单个空格之外的所有空格.VBA修剪将删除前导和尾随空格.
感谢MS为不同的功能使用相同的关键字.
修剪在开始和结束时删除多余的空格,而不是在字符串的中间.
Function CleanSpace(ByVal strIn As String) As String
strIn = Trim(strIn)
' // Replace all double space pairings with single spaces
Do While InStr(strIn, " ")
strIn = Replace(strIn, " ", " ")
Loop
CleanSpace = strIn
End Function
Run Code Online (Sandbox Code Playgroud)
从这里开始.
PS.这不是删除空格的最有效方法.我不会在许多很长的字符串或紧密循环中使用.它可能适合您的情况.
| 归档时间: |
|
| 查看次数: |
33334 次 |
| 最近记录: |