I want to replace all multiple spaces in cells in my range A1:K1000
. So if 2 or more spaces, then replace them with one space " "
.
My current code replaces spaces that are " "
(2) spaces. How to adjust it to work with 2 or more spaces? So it will handle cases like " "
, " "
, " "
etc.
Here is my code:
Sub RemoveSpaces()
Dim r1 As Range
Set r1 = ActiveSheet.Range("A1:K1000")
r1.Replace _
What:=Space(2), _
Replacement:=" ", _
SearchOrder:=xlByColumns, _
MatchCase:=True
Set r1 = r1.Find(What:=Space(2))
If Not r1 Is Nothing Then
Call RemoveSpaces
End If
End Sub