Trim Cells using VBA in Excel
- by Greg Reynolds
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 space. I cribbed the following code (I am completely new to VBA), but it doesn't seem to work. When I step through it in the debugger it looks like an infinite loop. Any help would be appreciated!
Sub DoTrim()
For Each cell In Selection.Cells
If cell.HasFormula = False Then
cell = Trim(cell)
End If
Next
End Sub