# Solved: Excel Macro Remove Spaces



## computerman29642 (Dec 4, 2007)

How would I go about removing potential spaces from start and end of a text in a worksheet?


----------



## Greencoast (Mar 26, 2009)

I believe you click on the main letter @ the top highlighting the entire column and then right click delete....


----------



## MRdNk (Apr 7, 2007)

Macro not needed. 
Try:
=TRIM(A1)

Or Do you actually mean workbook, in which more explanation needed?


----------



## computerman29642 (Dec 4, 2007)

Thanks MrdNK and Greencoast for the responses. 

I was able to get the Trim function to work within my macro.


----------



## Zack Barresse (Jul 25, 2004)

You can also download ASAP Utilities which has this functionality built into it (a free download). If you wanted this in a macro, it would be something like this...


```
Sub RemoveAllLeadingTrailingSpaces()
    Dim c As Range
    For Each c In Selection
        If Not c.HasFormula Then c.Value = Trim(c.Value)
    Next c
End Sub
```
_(untested)_

Very simplistic, and no error handling, but should fit 98% of the time.

HTH


----------



## computerman29642 (Dec 4, 2007)

Thanks Zack. 

I will play around with the code.


----------

