PC Review


Reply
Thread Tools Rate Thread

counting spaces

 
 
dstiefe
Guest
Posts: n/a
 
      2nd Nov 2008
I have a column full of names...the problem is there is random spacing before
the name...for example: " name" and in others it may be " name" while
others are " name"

how do I first count the number of spaces? then delete them so the name is
at the far left?

thank you
 
Reply With Quote
 
 
 
 
ShaneDevenshire
Guest
Posts: n/a
 
      2nd Nov 2008
Hi,

to remove unwanted space in cell A1, for example

=TRIM(A1)

Copy down as necessary. Then copy all the formulas, and choose Edit, Paste
Special, Values. You can then remove the originals and keep the clean
version.


--
Thanks,
Shane Devenshire


"dstiefe" wrote:

> I have a column full of names...the problem is there is random spacing before
> the name...for example: " name" and in others it may be " name" while
> others are " name"
>
> how do I first count the number of spaces? then delete them so the name is
> at the far left?
>
> thank you

 
Reply With Quote
 
ShaneDevenshire
Guest
Posts: n/a
 
      2nd Nov 2008
Oops,

I see you wanted to count the spaces. Do you want to count the number for
each cell or for all the cells?

This will count all the space in your text
=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))
assuming this are regular spacebar spaces. It will count the single space
between Happy Birthday.

This will count all the spaces that would be removed by TRIM
=LEN(A1)-LEN(TRIM(A1))
TRIM removes all leading and trailing spaces and all but one of the spaces
between word. It only works for spacebar spaces.

If you want to do the above for all the cells in column A but get one answer
in a single cell then

=SUMPRODUCT(LEN(A1:A100)-LEN(SUBSTITUTE(A1:A100," ","")))
or
=SUMPRODUCT(LEN(A1:A100)-LEN(TRIM(A1:A100)))

If this helps, please click the Yes button.
--
Thanks,
Shane Devenshire


"dstiefe" wrote:

> I have a column full of names...the problem is there is random spacing before
> the name...for example: " name" and in others it may be " name" while
> others are " name"
>
> how do I first count the number of spaces? then delete them so the name is
> at the far left?
>
> thank you

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      2nd Nov 2008
One way to fix it and count the names at the same time
Sub trimitupandcount()
mc = 0
For Each c In Range("a2:a22")
c.Value = LTrim(c)
If LCase(Left(c, 4)) = "name" Then mc = mc + 1
Next c
MsgBox mc
End Sub

If you DONT want to count the names,comment out the IF line


Sub trimitup()
For Each c In Range("a2:a22")
c.Value = LTrim(c)
Next c
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"dstiefe" <(E-Mail Removed)> wrote in message
news:FD3818E5-E7EF-400F-9F4E-(E-Mail Removed)...
>I have a column full of names...the problem is there is random spacing
>before
> the name...for example: " name" and in others it may be " name" while
> others are " name"
>
> how do I first count the number of spaces? then delete them so the name is
> at the far left?
>
> thank you


 
Reply With Quote
 
dstiefe
Guest
Posts: n/a
 
      3rd Nov 2008
my "trim" function is not working.. any thoughts on that?

"ShaneDevenshire" wrote:

> Hi,
>
> to remove unwanted space in cell A1, for example
>
> =TRIM(A1)
>
> Copy down as necessary. Then copy all the formulas, and choose Edit, Paste
> Special, Values. You can then remove the originals and keep the clean
> version.
>
>
> --
> Thanks,
> Shane Devenshire
>
>
> "dstiefe" wrote:
>
> > I have a column full of names...the problem is there is random spacing before
> > the name...for example: " name" and in others it may be " name" while
> > others are " name"
> >
> > how do I first count the number of spaces? then delete them so the name is
> > at the far left?
> >
> > thank you

 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      3rd Nov 2008
Perhaps the source of your data included non-breaking spaces (e.g., in a
browser):

http://www.mvps.org/dmcritchie/excel/join.htm#trimall

In article <9D1551B9-44B0-4E7B-9930-(E-Mail Removed)>,
dstiefe <(E-Mail Removed)> wrote:

> my "trim" function is not working.. any thoughts on that?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting Inbetween Spaces Peter Microsoft Excel Misc 11 14th Dec 2007 08:31 AM
RE: Counting Spaces =?Utf-8?B?QXJub2xkLUJhYnk=?= Microsoft Access Queries 0 15th Dec 2006 05:29 AM
Counting with spaces Tom G Microsoft Excel Discussion 2 7th Dec 2006 04:24 AM
counting spaces in a string xnman Microsoft Excel Programming 7 9th May 2004 03:06 PM
counting spaces in a string xnman Microsoft Excel Programming 4 16th Dec 2003 01:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 PM.