Forum Discussion
mesmrc
Jun 08, 2022Copper Contributor
If cell starts with a blankspace, delete it
Is there a macro I could run that would check all selected cells and if some of them have a space at the beginning of them, it would delete that space leaving just the rest of the content? For ex...
HansVogelaar
Jun 08, 2022MVP
Here you go.
Sub RemoveLeadingSpaces()
Dim cel As Range
Dim rng As Range
Application.ScreenUpdating = False
Set rng = Selection
With rng
Set cel = .Find(What:=" *", LookIn:=xlValues, LookAt:=xlWhole)
If Not cel Is Nothing Then
Do
cel.Value = LTrim(cel.Value)
Set cel = .FindNext(After:=cel)
Loop Until cel Is Nothing
End If
End With
Application.ScreenUpdating = True
End Sub- mesmrcJun 10, 2022Copper ContributorYou are the BEST in the biz! Thanks so much Hans.