How do I remove extra spaces faster, from a large range of cells containing text strings?
Let's say 5000+ cells.
Some ways I have tried include:
For Each c In range
c.Value = Trim(c.Value)
Next c
and
For Each c In range
c = WorksheetFunction.Trim(c)
Next c
and
For Each c In range
c.Value = Replace(c.Value, " ", " ")
Next c
Any ideas for speed improvement?
The loop is killing you. This will remove spaces in an entire column in one shot:
Adjust the range to suit. If you want to remove double spaces, then:
EDIT#1:
This version will replace doubles with singles and then check if there are still still doubles left!
You can re-run until you see done
EDIT#2:
based on Don Donoghue's comment, this version will run recursively until all double are converted to singles: