Hi,
I have the following code to remove excess spaces from the selected range (this could even be a single cell).
The problem is I get a run-time error if the selection is empty.
What I would like is to check the selection and if all cells are empty then pop-up a message "Selection is empty"
If not then carry on.
I have the following code to remove excess spaces from the selected range (this could even be a single cell).
The problem is I get a run-time error if the selection is empty.
What I would like is to check the selection and if all cells are empty then pop-up a message "Selection is empty"
If not then carry on.
VBA Code:
Sub Remove_Spaces()
Dim r As Range
With Application.WorksheetFunction
For Each r In Intersect(Selection, ActiveSheet.UsedRange)
r.Value = .Trim(r.Value)
Next r
End With
End Sub