Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trimming all selected cells

Status
Not open for further replies.

damrus

Technical User
Jun 22, 2008
24
0
0
PL
Hello!

How to trim each cell in chosen selection?
I mean... how to use this code:

Cells(10, 1) = Trim(Cells(10, 1))

in each cell of selection?

Regards
 






Hi,

I wouldn't recommend using the Selection method. However...
Code:
dim r as range
for each r in Selection
  with r
     .value = trim(.value)
  end with
next


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks:)
It works well. Anyway what do you recommend?
 
Hi damrus,

For performance reasons, it's usually better to specify the range to be acted upon, rather than selecting the cells and then acting on them. In this case, however, 'selection' is only being used to identify the range. Without it, you'd need some other way (eg an inputbox, which is slower and more error-prone).

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top