# Deleting spaces in cells

I have a VBA code sample that I use on a table to delete spaces in cells. I want to ask if someone has a better and quicker way to the Trim function on a table than what I have:

This is the sample:

If Sheets("Main").Cells(8, 6) = 1 Then
strName = Sheets("Main").Cells(8, 3)
Workbooks.Open Filename:="V:\á÷øåú ùëø\ãåçåú\ãåçåú çæåúééí\ãåçåú ìäîøä\exhr0101.csv"
Columns(7).Delete
Cells.Select
Selection.Copy
Windows("Trim all cells.xlsm").Activate
Sheets("Data").Select
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'ñâéøú çæåúé î÷åø
Windows("exhr0101.csv").Activate
ActiveWindow.Close
'áéöåò Trim
Windows("Trim all cells.xlsm").Activate
Sheets("Data").Select
For Each cell In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)
cell = WorksheetFunction.Trim(cell)
Next cell
'äãá÷ä áâéìéåï äãá÷ä
Cells.Select
Selection.Copy
Sheets("Target").Select
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False


Here is my specific trim:

For Each cell In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)
cell = WorksheetFunction.Trim(cell)
Next cell

• For a start is there a typed function Trim$? Feb 18 '18 at 14:41 • Application.Worksheetfunction.Trim() will leave a single space between words in a cell. Is this what you want?? Feb 18 '18 at 14:47 • @QHarr what do you mean Feb 18 '18 at 14:47 • @Gary'sStudent yes. I know what trim does. I want it to do it quicker Feb 18 '18 at 14:48 • Can you replace Trim with Trim$ without raising an error or it being swopped back to Trim. I can’t remember. Feb 18 '18 at 14:51

 With Activesheet.UsedRange