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
Works fine for me with one change - fourth line should be:
cell.Value = Trim(cell.Value)
Edit: If it appears to be stuck in a loop, I'd add
Debug.Print cell.Address
inside your For ... Next
loop to get a bit more info on what's happening.
I also suspect that Trim
only strips spaces - are you sure you haven't got some other kind of non-display character in there?
Worked for me perfectly as this:
Trims all selected cells. Beware of selecting full columns/rows :P.
Sub TrimSelected()
Dim rng As Range, cell As Range
Set rng = Selection
For Each cell In rng
cell = Trim(cell)
Next cell
End Sub