我在vba中编写代码来获取一个字符串并删除所有出现的单个空格,同时保留连续的空格。
这就是我现在所拥有的,但它只是删除所有空格并用破折号替换它们。
感谢您的任何帮助或指导!
Sub Main
'Nothing happens when the code executes the following string
CombineText("Job Hours Pay Labor %")
'When the following executes it should look like this
'Major-Group-Total 382 2,085.25
CombineText("Major Group Total 382 2,085.25")
End Sub
Sub CombineText(searchString As String)
a = Len(searchString)
For n = 1 To a
If Mid(searchString, n, 1) = Chr(32) Then
searchString = Application.Substitute(searchString, Mid(searchString, n, 1), "-")
End If
Next n
End Sub