I often receive data files that need some cleanup so I have created a macro to trim and remove carriage returns. It works well and is pretty quick (few seconds) when the range is, say, 1500 cells but its much slower (60+ secs) if there are 5-10k+. How can I speed this up? Or does someone have a different macro that accomplishes the same/similar thing?
Sub DeleteLeadingTrailingSpaces()
Application.ScreenUpdating = False
Set W = Application.Selection
Set W = Application.InputBox("Select one range that you want to remove leading and trailing spaces:", "RemoveLeadingAndTrailingSpaces", W.Address, Type:=8)
For Each R In W
R.Value = VBA.Trim(R.Value)
R.Value = Application.WorksheetFunction.Clean(R.Value)
Next
End Sub
Sub DeleteLeadingTrailingSpaces()
Application.ScreenUpdating = False
Set W = Application.Selection
Set W = Application.InputBox("Select one range that you want to remove leading and trailing spaces:", "RemoveLeadingAndTrailingSpaces", W.Address, Type:=8)
For Each R In W
R.Value = VBA.Trim(R.Value)
R.Value = Application.WorksheetFunction.Clean(R.Value)
Next
End Sub