PC Review


Reply
Thread Tools Rate Thread

Delete space after word

 
 
=?Utf-8?B?TmluaWVs?=
Guest
Posts: n/a
 
      20th Aug 2007
Hello,

I would like to make a macro that checks a worksheet and deletes any space
it finds at the end of a word in a cell, but only if it's the last word. In
other words "test " is what I'd like to fix, but "test test" or "test test
test" (etc) is not.

How could this be accomplished?

Thank you.


 
Reply With Quote
 
 
 
 
PCLIVE
Guest
Posts: n/a
 
      20th Aug 2007
One way:

For Each cell In Range("A1:A10")
cell.Value = Trim(cell.Value)
Next cell


Adjust your range as needed.

You could also do this via a formula.

With data in A1.
=TRIM(A1)
Then copy down as needed.
Copy entire column and Paste Special-Values only.

HTH,
Paul

--

"Niniel" <(E-Mail Removed)> wrote in message
news:FD4F2159-02EC-4556-9C4C-(E-Mail Removed)...
> Hello,
>
> I would like to make a macro that checks a worksheet and deletes any space
> it finds at the end of a word in a cell, but only if it's the last word.
> In
> other words "test " is what I'd like to fix, but "test test" or "test test
> test" (etc) is not.
>
> How could this be accomplished?
>
> Thank you.
>
>



 
Reply With Quote
 
=?Utf-8?B?VG9wcGVycw==?=
Guest
Posts: n/a
 
      20th Aug 2007
TRIM function?

"Niniel" wrote:

> Hello,
>
> I would like to make a macro that checks a worksheet and deletes any space
> it finds at the end of a word in a cell, but only if it's the last word. In
> other words "test " is what I'd like to fix, but "test test" or "test test
> test" (etc) is not.
>
> How could this be accomplished?
>
> Thank you.
>
>

 
Reply With Quote
 
=?Utf-8?B?TmluaWVs?=
Guest
Posts: n/a
 
      20th Aug 2007
Would this also work for the entire worksheet? I don't want to have to
specify a range.

"PCLIVE" wrote:

> One way:
>
> For Each cell In Range("A1:A10")
> cell.Value = Trim(cell.Value)
> Next cell
>
>
> Adjust your range as needed.
>
> You could also do this via a formula.
>
> With data in A1.
> =TRIM(A1)
> Then copy down as needed.
> Copy entire column and Paste Special-Values only.
>
> HTH,
> Paul
>
> --
>
> "Niniel" <(E-Mail Removed)> wrote in message
> news:FD4F2159-02EC-4556-9C4C-(E-Mail Removed)...
> > Hello,
> >
> > I would like to make a macro that checks a worksheet and deletes any space
> > it finds at the end of a word in a cell, but only if it's the last word.
> > In
> > other words "test " is what I'd like to fix, but "test test" or "test test
> > test" (etc) is not.
> >
> > How could this be accomplished?
> >
> > Thank you.
> >
> >

>
>
>

 
Reply With Quote
 
PCLIVE
Guest
Posts: n/a
 
      20th Aug 2007
Yes, it would...but I wouldn't suspect that you'd want to bogg down your
system by checking of the 168,099,840 cells (minimum depending on excel
version). Find the column and row at which your data stops, and adjust your
range accordingly. You should be able to do this by pressing Ctrl+End.

Regards,
Paul

--

"Niniel" <(E-Mail Removed)> wrote in message
news:45E203D9-AEC4-481D-BA09-(E-Mail Removed)...
> Would this also work for the entire worksheet? I don't want to have to
> specify a range.
>
> "PCLIVE" wrote:
>
>> One way:
>>
>> For Each cell In Range("A1:A10")
>> cell.Value = Trim(cell.Value)
>> Next cell
>>
>>
>> Adjust your range as needed.
>>
>> You could also do this via a formula.
>>
>> With data in A1.
>> =TRIM(A1)
>> Then copy down as needed.
>> Copy entire column and Paste Special-Values only.
>>
>> HTH,
>> Paul
>>
>> --
>>
>> "Niniel" <(E-Mail Removed)> wrote in message
>> news:FD4F2159-02EC-4556-9C4C-(E-Mail Removed)...
>> > Hello,
>> >
>> > I would like to make a macro that checks a worksheet and deletes any
>> > space
>> > it finds at the end of a word in a cell, but only if it's the last
>> > word.
>> > In
>> > other words "test " is what I'd like to fix, but "test test" or "test
>> > test
>> > test" (etc) is not.
>> >
>> > How could this be accomplished?
>> >
>> > Thank you.
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?TmluaWVs?=
Guest
Posts: n/a
 
      20th Aug 2007
Ok. Since the number of rows isn't constant, I figured I'd specify a very
generous range, say 2k rows, but that didn't work. I saw activity (the cursor
flickered for a couple of seconds), but the trailing spaces in my 2 test
cells were not deleted.

For Each cell In Range("b4:b2222")
cell.Value = Trim(cell.Value)
Next cell
 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      20th Aug 2007
Or use ActiveSheet.UsedRange which in most cases will not include the entire
worksheet.


Gord Dibben MS Excel MVP

On Mon, 20 Aug 2007 14:38:20 -0700, Niniel <(E-Mail Removed)>
wrote:

>Ok. Since the number of rows isn't constant, I figured I'd specify a very
>generous range, say 2k rows, but that didn't work. I saw activity (the cursor
>flickered for a couple of seconds), but the trailing spaces in my 2 test
>cells were not deleted.
>
> For Each cell In Range("b4:b2222")
> cell.Value = Trim(cell.Value)
> Next cell


 
Reply With Quote
 
PCLIVE
Guest
Posts: n/a
 
      20th Aug 2007
You might try clean instead of trim.

--

"Niniel" <(E-Mail Removed)> wrote in message
news:34C22504-CD8C-48BA-88D4-(E-Mail Removed)...
> Ok. Since the number of rows isn't constant, I figured I'd specify a very
> generous range, say 2k rows, but that didn't work. I saw activity (the
> cursor
> flickered for a couple of seconds), but the trailing spaces in my 2 test
> cells were not deleted.
>
> For Each cell In Range("b4:b2222")
> cell.Value = Trim(cell.Value)
> Next cell



 
Reply With Quote
 
=?Utf-8?B?TmluaWVs?=
Guest
Posts: n/a
 
      20th Aug 2007
No, I think Trim is exactly what I need, I just have to get it to work in my
macro.

"PCLIVE" wrote:

> You might try clean instead of trim.


 
Reply With Quote
 
Pete_UK
Guest
Posts: n/a
 
      20th Aug 2007
Note that those "spaces" not removed by TRIM may be the non-breaking
space character (code = 160), rather than a normal space (code = 32).
TRIM will not remove these.

Hope this helps.

Pete

On Aug 20, 11:10 pm, Niniel <Nin...@discussions.microsoft.com> wrote:
> No, I think Trim is exactly what I need, I just have to get it to work in my
> macro.
>
>
>
> "PCLIVE" wrote:
> > You might try clean instead of trim.- Hide quoted text -

>
> - Show quoted text -



 
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
How to delete large space before footnote (Word 2007)? =?Utf-8?B?Uk5X?= Microsoft Word Document Management 4 3rd Jan 2009 04:22 PM
Blank Space - Cannot Delete - MS Word 2003 Ellis Place Microsoft Word Document Management 2 14th Nov 2008 02:46 PM
Can't delete text in Word by hightlighting and hitting space bar! =?Utf-8?B?Q2F0aHkgQw==?= Microsoft Word Document Management 1 29th Jul 2006 07:31 PM
In WORD, my space bar will not delete what I highlight. =?Utf-8?B?YmlsbHlw?= Microsoft Word Document Management 1 13th Dec 2005 03:54 PM
Why does Word leave a blank space when you delete a whole paragraph? DJ Kim Microsoft Word New Users 1 25th Mar 2004 07:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:17 PM.