Excel VBA Macro to TRIM Selection – Episode 2268

Kristin wants to have a fast way to remove leading a trailing spaces from an entire range of Excel cells. In this episode, a 7-line macro to solve this problem.
Sub TrimSelection()
Dim cell As Range
For Each cell In Selection
If Not cell.HasFormula Then
cell.Value = Trim(cell.Value)
End If
Next cell
End Sub

View on YouTube