Found this macro online and while studying it, I came up with two questions that I haven't been able to find an answer for:
First, is it necessary to declare the object variables MyRange and MyCell? What advantage(s) does this provide by doing it?
Second, based on a previous question I posted, is it redundant to check whether the cell is empty or not before its value is trimmed. What is the advantage of this check? Is it merely to save compiling effort/time? Or are there other technical reasons?
Sub TrimSpaces()
Dim MyRange As Range
Dim MyCell As Range
Select Case MsgBox(“Workbook First?”, vbYesNoCancel)
Case Is = vbYes
ThisWorkbook.Save
Case Is = vbCancel
Exit Sub
End Select
Set MyRange = Selection
For Each MyCell in MyRange
If Not IsEmpty(MyCell) Then
MyCell = Trim(MyCell)
End If
Next MyCell
End Sub