PDA

View Full Version : Solved: Remove spaces from the beginning and end of a cell



parscon
12-26-2012, 05:43 AM
Dear friend ,
I need a VBA code that Remove spaces from the beginning and end of a cell in column A .

Thank you .

CodeNinja
12-26-2012, 06:38 AM
Sub removeSpaces()
For i = 1 To Sheet1.Range("A65536").End(xlUp).Row
Sheet1.Cells(i, 1) = Trim(Sheet1.Cells(i, 1))
Next i

End Sub

Paul_Hossler
12-26-2012, 07:26 AM
In 2007/2010 there's more that 65,536 rows possible on a sheet



Option Explicit
Sub removeSpaces()
Dim rCell As Range

On Error GoTo NiceExit

For Each rCell In ActiveSheet.Columns(1).SpecialCells(xlCellTypeConstants, xlTextValues).Cells
rCell.Value = Trim(rCell.Value)
Next

NiceExit:
On Error GoTo 0

End Sub


Paul

parscon
12-27-2012, 06:13 AM
Thank you very much .