How to remove spaces in between text?

后端 未结 10 586
日久生厌
日久生厌 2021-01-13 00:00

Why trim is not working in VBA?

for i = 3 to 2000
activesheet.cells(i,\"C\").value = trim(Activesheet.cells(i,\"C\").value)
next i

It is un

10条回答
  •  一整个雨季
    2021-01-13 00:29

    Sometimes what looks to be a space is not a space but a character that cannot be displayed. Use the ASC function to get the integer value of the character. Then use the following code:

    Function CleanSpace(ByVal StrIn As String) As String
        StrIn = Trim(StrIn)
    
      ' Searches string from end and trims off excess ascii characters
    
      Dim StrLength As Integer
      Dim SingleChar As Integer
      Dim StrPosition As Integer
    
      SingleChar = 1
    
      StrLength = Len(StrIn)
      StrPosition = StrLength - 1
    
        Do Until Asc(Mid(StrIn, StrPosition, SingleChar)) <> 0
            StrPosition = StrPosition - 1
        Loop
      StrIn = Mid(StrIn, 1, StrPosition)
    
    End Function
    

提交回复
热议问题