I have what seems like a simple problem with some data in Excel. I have a lot of data with leading spaces pasted from a web table, and I would like to get rid of the initial
If you have a non-printing character at the front of the string try this
Option Explicit
Sub DoTrim()
Dim cell As Range
Dim str As String
Dim nAscii As Integer
For Each cell In Selection.Cells
If cell.HasFormula = False Then
str = Trim(CStr(cell))
If Len(str) > 0 Then
nAscii = Asc(Left(str, 1))
If nAscii < 33 Or nAscii = 160 Then
If Len(str) > 1 Then
str = Right(str, Len(str) - 1)
Else
strl = ""
End If
End If
End If
cell=str
End If
Next
End Sub