#1   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Trim question

I want to use the following code to remove space at the end of the value in
each cell in a coulmn but the space is still there. Any ideas what is going
on?
Thanks.

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.UsedRange.Rows.Count

For Each c In Range("A2:A" & ClastRow).Cells
'c = Mid(c, 1, Len(c) - 1)
c = Trim(c)
Next c

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,393
Default Trim question

TRIM remove only the space defined by CHAR(32)
There is also the 'no-breaking' space, CHAR(160)
Have a look at this site; lots of suggestions
http://office.microsoft.com/en-us/ex...561311033.aspx

and Ron has good stuff at
http://www.rondebruin.nl/clean.htm

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Ayo" wrote in message
...
I want to use the following code to remove space at the end of the value in
each cell in a coulmn but the space is still there. Any ideas what is
going
on?
Thanks.

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.UsedRange.Rows.Count

For Each c In Range("A2:A" & ClastRow).Cells
'c = Mid(c, 1, Len(c) - 1)
c = Trim(c)
Next c

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Trim question

Maybe

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Set cl = Range("A2:A" & ClastRow)
For Each c In cl
c = WorksheetFunction.Trim(c)
Next c

End Sub

Mike

"Ayo" wrote:

I want to use the following code to remove space at the end of the value in
each cell in a coulmn but the space is still there. Any ideas what is going
on?
Thanks.

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.UsedRange.Rows.Count

For Each c In Range("A2:A" & ClastRow).Cells
'c = Mid(c, 1, Len(c) - 1)
c = Trim(c)
Next c

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Trim question

That didn't work. The space is still there.

"Mike H" wrote:

Maybe

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Set cl = Range("A2:A" & ClastRow)
For Each c In cl
c = WorksheetFunction.Trim(c)
Next c

End Sub

Mike

"Ayo" wrote:

I want to use the following code to remove space at the end of the value in
each cell in a coulmn but the space is still there. Any ideas what is going
on?
Thanks.

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.UsedRange.Rows.Count

For Each c In Range("A2:A" & ClastRow).Cells
'c = Mid(c, 1, Len(c) - 1)
c = Trim(c)
Next c

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Trim question

Good point

"Bernard Liengme" wrote:

TRIM remove only the space defined by CHAR(32)
There is also the 'no-breaking' space, CHAR(160)
Have a look at this site; lots of suggestions
http://office.microsoft.com/en-us/ex...561311033.aspx

and Ron has good stuff at
http://www.rondebruin.nl/clean.htm

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Ayo" wrote in message
...
I want to use the following code to remove space at the end of the value in
each cell in a coulmn but the space is still there. Any ideas what is
going
on?
Thanks.

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.UsedRange.Rows.Count

For Each c In Range("A2:A" & ClastRow).Cells
'c = Mid(c, 1, Len(c) - 1)
c = Trim(c)
Next c

End Sub






  #6   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Trim question

How do I write CHAR(160) in VBA code?

"Bernard Liengme" wrote:

TRIM remove only the space defined by CHAR(32)
There is also the 'no-breaking' space, CHAR(160)
Have a look at this site; lots of suggestions
http://office.microsoft.com/en-us/ex...561311033.aspx

and Ron has good stuff at
http://www.rondebruin.nl/clean.htm

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Ayo" wrote in message
...
I want to use the following code to remove space at the end of the value in
each cell in a coulmn but the space is still there. Any ideas what is
going
on?
Thanks.

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.UsedRange.Rows.Count

For Each c In Range("A2:A" & ClastRow).Cells
'c = Mid(c, 1, Len(c) - 1)
c = Trim(c)
Next c

End Sub




  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Trim question

For Each c In Range("A2:A" & ClastRow).Cells
c.Replace what:=Chr(160), replacement:=""
Next c


Gord Dibben MS Excel MVP

On Fri, 18 Jul 2008 12:07:03 -0700, Ayo wrote:

How do I write CHAR(160) in VBA code?

"Bernard Liengme" wrote:

TRIM remove only the space defined by CHAR(32)
There is also the 'no-breaking' space, CHAR(160)
Have a look at this site; lots of suggestions
http://office.microsoft.com/en-us/ex...561311033.aspx

and Ron has good stuff at
http://www.rondebruin.nl/clean.htm

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Ayo" wrote in message
...
I want to use the following code to remove space at the end of the value in
each cell in a coulmn but the space is still there. Any ideas what is
going
on?
Thanks.

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.UsedRange.Rows.Count

For Each c In Range("A2:A" & ClastRow).Cells
'c = Mid(c, 1, Len(c) - 1)
c = Trim(c)
Next c

End Sub





  #8   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Trim question

Thanks Gord. Works perfectly.

"Gord Dibben" wrote:

For Each c In Range("A2:A" & ClastRow).Cells
c.Replace what:=Chr(160), replacement:=""
Next c


Gord Dibben MS Excel MVP

On Fri, 18 Jul 2008 12:07:03 -0700, Ayo wrote:

How do I write CHAR(160) in VBA code?

"Bernard Liengme" wrote:

TRIM remove only the space defined by CHAR(32)
There is also the 'no-breaking' space, CHAR(160)
Have a look at this site; lots of suggestions
http://office.microsoft.com/en-us/ex...561311033.aspx

and Ron has good stuff at
http://www.rondebruin.nl/clean.htm

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Ayo" wrote in message
...
I want to use the following code to remove space at the end of the value in
each cell in a coulmn but the space is still there. Any ideas what is
going
on?
Thanks.

Private Sub cmdRemoveSpace_Click()
Dim ClastRow As Integer, c As Range, cl As Range
ClastRow = ActiveSheet.UsedRange.Rows.Count

For Each c In Range("A2:A" & ClastRow).Cells
'c = Mid(c, 1, Len(c) - 1)
c = Trim(c)
Next c

End Sub





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
TRIM s99drf New Users to Excel 3 April 27th 07 09:46 PM
Using =TRIM() Chuda Excel Worksheet Functions 6 November 9th 06 04:05 PM
Another, sort of trim question stapleton2308 Excel Discussion (Misc queries) 2 February 15th 06 07:54 PM
Trim stapleton2308 Excel Discussion (Misc queries) 4 February 15th 06 07:09 PM
TRIM? Cthulhu Excel Worksheet Functions 10 February 10th 05 10:36 PM


All times are GMT +1. The time now is 05:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"