Trim the entire range

G

Guest

Hi,

I have the following code that loops through a certain range.
For Each cel In ADINames
cel.Value = Trim(cel.Value)
Next cel

Can this be done on the entire range at once, i.e, w/o looping?

Thank you,
 
Joined
Nov 5, 2007
Messages
18
Reaction score
0
you can use an array formula ie:

dim rng as range, trimRng as range

set rng = sheets("Spare Sheet").resize(trimRng.rows.count, trimRng.columns.count)

application.screenupdating = false
rng.formulaarray = "=trim(trimRng)"
rng.parent.activate
rng.select
selection.copy
trimRng.parent.activate
trimRng.select
activesheet.pastespecial Paste:=xlPasteValues
with application
.cutcopymode = false
.screenupdating = false
end with
HTH
 
D

Dave Peterson

If the range is a single column, you could try:

Selecting the range
data|text to columns
Fixed width and then click finish.

If you need a macro, record it when you do it manually.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top