Is it Possible

  • Thread starter Thread starter John
  • Start date Start date
J

John

Is is possible to determine the number of blank characters entered in a
cell? What I mean by Blank, is when the user uses the spacebar to clear the
contents of the cell

I have used =LEN but that returns a value for all characters blank and
otherwise.


Thanks
 
=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Thanks Bob, very very clever


Bob Phillips said:
=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
One twist on this Bob, is that, is it possible to just count the Blanks to
the left of the first word. In my cell two words entered are valid but that
means a blank between the first and second, so I would have to allow that.
My idea is that when I get a value >0 then I delete the contents of A1, but
if two words are typed in that would return 1 and in that case I would
incorrectly delete. Thus blanks before the first word are the entries that
are invalid
 
John said:
One twist on this Bob, is that, is it possible to just count the Blanks to
the left of the first word. In my cell two words entered are valid but that
means a blank between the first and second, so I would have to allow that.
My idea is that when I get a value >0 then I delete the contents of A1, but
if two words are typed in that would return 1 and in that case I would
incorrectly delete. Thus blanks before the first word are the entries that
are invalid
....

If you want to eliminate leading spaces and would also accept eliminating
any trailing spaces and compressing any sequences of multiple spaces between
words into single spaces, use the TRIM function.

If you really want just the number of leading spaces, try

=FIND(LEFT(TRIM(A1),1),A1)-1
 
Thanks Harlan, I can work with that


Harlan Grove said:
...

If you want to eliminate leading spaces and would also accept eliminating
any trailing spaces and compressing any sequences of multiple spaces
between words into single spaces, use the TRIM function.

If you really want just the number of leading spaces, try

=FIND(LEFT(TRIM(A1),1),A1)-1
 

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

Back
Top