Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default trim a range object

I have a nice range defined and I want to trim up all the cells.
Can't I do something like


Application.WorksheetFunction.Trim(rng)
or
Application.WorksheetFunction.Trim(rng.Value2);
or
....

I can build a loop, but geezzz, these range objects are too nice to
have to fool around like that. Is there an enumerator somewhere.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default trim a range object

hi
the trim function trims leading and trailing spaces from a string.
a range object requires a defined address such as A1 or A1:D5 or VB
regurgitates
error messages. i have never heard of anyone trying to trim rannge objects
and i doubt that it can be done.
what are you trying to do?

Regards
FSt1

"cate" wrote:

I have a nice range defined and I want to trim up all the cells.
Can't I do something like


Application.WorksheetFunction.Trim(rng)
or
Application.WorksheetFunction.Trim(rng.Value2);
or
....

I can build a loop, but geezzz, these range objects are too nice to
have to fool around like that. Is there an enumerator somewhere.

Thanks
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default trim a range object

hi
afterthought.
are you trying to trim values within the range object?

regards
FSt1

"FSt1" wrote:

hi
the trim function trims leading and trailing spaces from a string.
a range object requires a defined address such as A1 or A1:D5 or VB
regurgitates
error messages. i have never heard of anyone trying to trim rannge objects
and i doubt that it can be done.
what are you trying to do?

Regards
FSt1

"cate" wrote:

I have a nice range defined and I want to trim up all the cells.
Can't I do something like


Application.WorksheetFunction.Trim(rng)
or
Application.WorksheetFunction.Trim(rng.Value2);
or
....

I can build a loop, but geezzz, these range objects are too nice to
have to fool around like that. Is there an enumerator somewhere.

Thanks
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default trim a range object

Sub trimrng()
Dim r As Range
Set r = [A1]
r.Value = Trim(r.Value)
End Sub

regards
FSt1

"FSt1" wrote:

hi
afterthought.
are you trying to trim values within the range object?

regards
FSt1

"FSt1" wrote:

hi
the trim function trims leading and trailing spaces from a string.
a range object requires a defined address such as A1 or A1:D5 or VB
regurgitates
error messages. i have never heard of anyone trying to trim rannge objects
and i doubt that it can be done.
what are you trying to do?

Regards
FSt1

"cate" wrote:

I have a nice range defined and I want to trim up all the cells.
Can't I do something like


Application.WorksheetFunction.Trim(rng)
or
Application.WorksheetFunction.Trim(rng.Value2);
or
....

I can build a loop, but geezzz, these range objects are too nice to
have to fool around like that. Is there an enumerator somewhere.

Thanks
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default trim a range object

Sub trimrng()
Dim r As Range
Dim lr As Long
lr = Cells(Rows.Count, "a").End(xlUp).Row
Set r = Range("A1:A" & lr)
For Each c In r
c.Value = Trim(c.Value)
Next c
End Sub

regard
FSt1

"FSt1" wrote:

Sub trimrng()
Dim r As Range
Set r = [A1]
r.Value = Trim(r.Value)
End Sub

regards
FSt1

"FSt1" wrote:

hi
afterthought.
are you trying to trim values within the range object?

regards
FSt1

"FSt1" wrote:

hi
the trim function trims leading and trailing spaces from a string.
a range object requires a defined address such as A1 or A1:D5 or VB
regurgitates
error messages. i have never heard of anyone trying to trim rannge objects
and i doubt that it can be done.
what are you trying to do?

Regards
FSt1

"cate" wrote:

I have a nice range defined and I want to trim up all the cells.
Can't I do something like


Application.WorksheetFunction.Trim(rng)
or
Application.WorksheetFunction.Trim(rng.Value2);
or
....

I can build a loop, but geezzz, these range objects are too nice to
have to fool around like that. Is there an enumerator somewhere.

Thanks
.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default trim a range object

There is an enumerator ... see the 4th post by FSt1 on how to implement it.

When you initially set up your large, multi-cell range with something like:
Set rng = Worksheets("Sheet1").Range("A1:Z44")
later on Excel is smart enough to know that when you use the
For Each command, that "Each" refers to an individual cell (also a range
object).

Specifically, your Dim Statements would be like this:
Dim rng As Range
dim anyCell as Range

Then code goes on like FSt1 showed. But FSt1 didn't show the definition of
'c' in the code, to be more complete/proper it should look something like:

Sub trimrng()
Dim r As Range
Dim c As Range 'added for clarity
Dim lr As Long
lr = Cells(Rows.Count, "a").End(xlUp).Row
Set r = Range("A1:A" & lr)
For Each c In r
c.Value = Trim(c.Value)
Next c
End Sub


"cate" wrote:

I have a nice range defined and I want to trim up all the cells.
Can't I do something like


Application.WorksheetFunction.Trim(rng)
or
Application.WorksheetFunction.Trim(rng.Value2);
or
....

I can build a loop, but geezzz, these range objects are too nice to
have to fool around like that. Is there an enumerator somewhere.

Thanks
.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default trim a range object

On Mar 23, 11:13*pm, JLatham
wrote:
There is an enumerator ... see the 4th post by FSt1 on how to implement it.

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
Find End in Undefined Range Select Range Trim SteveT Excel Programming 4 November 29th 07 06:54 PM
Trim the entire range Greg Excel Programming 1 November 6th 07 07:36 PM
returning pivottable object from a range object Grant Excel Programming 2 September 27th 04 02:22 AM
Range object to Array object conversion Myrna Larson[_2_] Excel Programming 1 August 1st 03 02:27 AM
Range object to Array object conversion Tom Ogilvy Excel Programming 0 August 1st 03 12:16 AM


All times are GMT +1. The time now is 04:11 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"