I am trying to remove the leading and trailing spaces in an excel sheet. I have a code that is currently doing that but it is running through the entire sheet. I would like to select a range, instead of the whole sheet to save time.
I tried using a code already but i need to simplify to make the process faster.
Dim r As Range
For Each r In ActiveSheet.UsedRange
v = r.Value
If v <> "" Then
If Not r.HasFormula Then
r.Value = Trim(v)
End If
End If
Next r
This code will remove spaces from the entire sheet.
UsedRange, why notSelection? Or get the range from an input box.