Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default TRIM function - for the whole sheet

Request your guidance on how can I execute the trim
function for all the cells in a sheet. Is there any VB
code or macro which can do this?

Regards,
  #2   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default TRIM function - for the whole sheet

It would take a long time to complete. you might be better
selecting the range and working with that.

Sub TrimSelection()

For Each c In Selection
c.Value = Trim(c)
Next c

End Sub

Sub TrimRange()
Dim rng As Range
Set rng = Range("A1:z22") 'change this to suit
For Each c In rng
c.Value = Trim(c)
Next c
End Sub

Regards
Peter

-----Original Message-----
Request your guidance on how can I execute the trim
function for all the cells in a sheet. Is there any VB
code or macro which can do this?

Regards,
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default TRIM function - for the whole sheet

You can use the UsedRange property of the Worksheet object. This will return
the maximum range (in one area) that is used. So you won't have to go
through the entire worksheet (most of it is not actually used).

Set rng = ActiveWorksheet.UsedRange

Alan

wrote in message
...
It would take a long time to complete. you might be better
selecting the range and working with that.

Sub TrimSelection()

For Each c In Selection
c.Value = Trim(c)
Next c

End Sub

Sub TrimRange()
Dim rng As Range
Set rng = Range("A1:z22") 'change this to suit
For Each c In rng
c.Value = Trim(c)
Next c
End Sub

Regards
Peter

-----Original Message-----
Request your guidance on how can I execute the trim
function for all the cells in a sheet. Is there any VB
code or macro which can do this?

Regards,
.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default TRIM function - for the whole sheet

Thanks Alan and Peter.
I will try out right now and let you know the results. But
I think this is exectly what I want and it must work.

Thanks again.
Shetty

-----Original Message-----
You can use the UsedRange property of the Worksheet

object. This will return
the maximum range (in one area) that is used. So you

won't have to go
through the entire worksheet (most of it is not actually

used).

Set rng = ActiveWorksheet.UsedRange

Alan

wrote in message
...
It would take a long time to complete. you might be

better
selecting the range and working with that.

Sub TrimSelection()

For Each c In Selection
c.Value = Trim(c)
Next c

End Sub

Sub TrimRange()
Dim rng As Range
Set rng = Range("A1:z22") 'change this to suit
For Each c In rng
c.Value = Trim(c)
Next c
End Sub

Regards
Peter

-----Original Message-----
Request your guidance on how can I execute the trim
function for all the cells in a sheet. Is there any VB
code or macro which can do this?

Regards,
.



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default TRIM function - for the whole sheet

You can narrow down the magnitude of your work by only working on string
constants

Dim rng as Range, cell as Range
On error resume next
set rng = ActiveSheet.Cells.SpecialCells(xlConstants,xlTextV alues)
On Error goto 0
if not rng is nothing then
for each cell in rng
cell.Value = application.Trim(cell.Value)
Next
Else
msgbox "No text values found"
End if


--
Regards,
Tom Ogilvy


"Shetty" wrote in message
...
Thanks Alan and Peter.
I will try out right now and let you know the results. But
I think this is exectly what I wantAmust work.

Thanks again.
Shetty

-----Original Message-----
You can use the UsedRange property of the Worksheet

object. This will return
the maximum range (in one area) that is used. So you

won't have to go
through the entire worksheet (most of it is not actually

used).

Set rng = ActiveWorksheet.UsedRange

Alan

wrote in message
...
It would take a long time to complete. you might be

better
selecting the range and working with that.

Sub TrimSelection()

For Each c In Selection
c.Value = Trim(c)
Next c

End Sub

Sub TrimRange()
Dim rng As Range
Set rng = Range("A1:z22") 'change this to suit
For Each c In rng
c.Value = Trim(c)
Next c
End Sub

Regards
Peter

-----Original Message-----
Request your guidance on how can I execute the trim
function for all the cells in a sheet. Is there any VB
code or macro which can do this?

Regards,
.



.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default TRIM function - for the whole sheet

Tom Ogilvy wrote:
You can narrow down the magnitude of your work by only working on
string
constants

Dim rng as Range, cell as Range
--
Regards,
Tom Ogilvy


Tom,

Thanks for your wonderful explanations and your various posts helping
people like us.

I need to ask you help on these 2 things:

1. If I want to apply the code only to a particular column and not the
whole sheet (not ALL) how do I do it ? I want to apply worksheet
function proper to a column named NAME.

2. Second question when I use Proper function in Excel (97?) it does
not change these names properly. How do I achieve this

joan vannocker-sampson should be Joan VanNocker-Sampson john d mckeon
should be John D McKeon
arthur l dewyse should be Arthur L DeWyse

Thanks in advance.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default TRIM function - for the whole sheet

Is Name a defined name such as Insert=Name=Define or do you mean the
column has the word Name in the first row. This should handle both, but you
could remove what is not appropriate.

Dim rng as Range, cell as Range
Dim rng1 as Range
On Error Resume Next
set rng1 = Thisworkbook.Names("Name").RefersToRange
On Error goto 0
if rng1 is nothing then
for i = 1 to 256
if lcase(cells(1,i).Value) = "name" then
set rng1 = Cells(1,i).EntireColumn.Cells
exit for
End if
Next
End if
if rng1 is nothing then
msgbox "Can't find column"
Exit Sub
End if
On error resume next
set rng = ActiveSheet.Cells.SpecialCells(xlConstants,xlTextV alues)
On Error goto 0
if not rng is nothing then
for each cell in rng
cell.Value = strConv(application.Trim(cell.Value),vbProperCase)
Next
Else
msgbox "No text values found"
End if


Proper and StrConv with the vbProperCase argument are not smart enough to
know capitalization rules for Names. The just capitalize the first letter
of each word.

I think you would need some type of dictionary that list all the unique
capitalizations or code the rules.

--
Regards,
Tom Ogilvy


"ssexcel" wrote in message
...
Tom Ogilvy wrote:
You can narrow down the magnitude of your work by only working on
string
constants

Dim rng as Range, cell as Range
--
Regards,
Tom Ogilvy


Tom,

Thanks for your wonderful explanations and your various posts helping
people like us.

I need to ask you help on these 2 things:

1. If I want to apply the code only to a particular column and not the
whole sheet (not ALL) how do I do it ? I want to apply worksheet
function proper to a column named NAME.

2. Second question when I use Proper function in Excel (97?) it does
not change these names properly. How do I achieve this

joan vannocker-sampson should be Joan VanNocker-Sampson john d mckeon
should be John D McKeon
arthur l dewyse should be Arthur L DeWyse

Thanks in advance.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default TRIM function - for the whole sheet

Tom Ogilvy wrote:
Is Name a defined name such as Insert=Name=Define or do you mean
the
column has the word Name in the first row. This should handle both,
but you
could remove what is not appropriate.
Proper and StrConv with the vbProperCase argument are not smart
enough to
know capitalization rules for Names. The just capitalize the first
letter
of each word.

I think you would need some type of dictionary that list all the
unique
capitalizations or code the rules.



Thanks for your response. I meant the column with heading Name. I
would come back to you in case I face any difficulty.

Best regards



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

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
Function =Trim() Dowitch Excel Worksheet Functions 5 April 29th 09 10:22 PM
Function =Trim() Dowitch Excel Worksheet Functions 1 April 29th 09 06:49 PM
Len & Trim Function Daren Excel Worksheet Functions 6 October 14th 08 02:32 PM
how to trim a whole excel sheet? fun Excel Worksheet Functions 2 June 23rd 06 07:51 AM
Trim Function Matt M HMS Excel Worksheet Functions 5 November 21st 05 10:46 PM


All times are GMT +1. The time now is 04:18 PM.

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"