Removing All Spaces in String

后端 未结 7 1434
滥情空心
滥情空心 2021-01-11 13:33

I created a macro for removing all whitespace in a string, specifically an email address. However it only removes about 95% of the whitespace, and leaves a few.

My c

7条回答
  •  佛祖请我去吃肉
    2021-01-11 13:53

    I copied a HTML table with data and pasted in excel but the cells were filled with unwanted space and all methods posted here didn't work so I debugged and I discovered that it wasn't actually space chars (ASCII 32) it was Non-breaking space) (ASCII 160) or HTML  

    So to make it work with that Non-breaking space char I did this:

    Sub NoSpaces()
        Dim w As Range
    
        For Each w In Selection.Cells
            w.Value = Replace(w.Value, " ", vbNullString)
            w.Value = Replace(w.Value, Chr(160), vbNullString)
        Next
    End Sub
    

提交回复
热议问题