Delete space at beginning


R

rexmann

Hi All

Is it possible to delete the space at the beginning of a cell of data? I
have a list of addresses for a mail merge and some (not all) have a space at
the beginning of the data. Ideally the find and replace (rather than a
formula) would be best.

Example (in the first one the address has a space):
1 Corsica Street
22 High Street

Any help greatly appreciated

Kind regards

Rexmann
 
Ad

Advertisements

G

Gary''s Student

Select the cells you want to adjust and run this small macro:

Sub spaceSaver()
For Each r In Selection
If IsEmpty(r) Then
Else
If Left(r.Value, 1) = " " Then
r.Value = Right(r.Value, Len(r.Value) - 1)
End If
End If
Next
End Sub
 
B

Bob Phillips

Dim LastRow As Long
Dim i As Long

With ActiveSheet

.Cells(.Rows.Count,"A").End(xlUp).Row
For i = 1To LastRow

.Cells(i,"A").Value = Trim(.Cells(i,"A").Value)
Next i

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
R

rexmann

Brilliant, thank you, that worked great.

I have tried to mess around with it and get it to do something else. Is it
easy to modify to make it delete spaces at the end?

Any ideas gratefully received

Rexmann
 
Ad

Advertisements

B

Bob Phillips

See my offering.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top