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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim Cells in multiple columns - excel 1

Status
Not open for further replies.

jupops

Technical User
May 15, 2003
72
GB
Good Evening All

Can you please help?

Basically I am trying to Trim cells in multiple columns is excel.

I can do a single column at a time with (which is restricted to Row 3000 – to save time):

Sub Trim()

Dim i As Long

For i = 1 To Range("B3000").End(xlUp).Row
Range("B" & i).Value = Trim(Range("B" & i).Value)
Next

End Sub

But I wish to pick all the cells column B upwards which have text in them because each report has a different length and may have may go up to column K

If you can help I would be grateful

Regards
Jupops
 


hi,
Code:
Sub Trim()

  Dim r as range, c as range

  with activesheet.usedrange

    For each r in range(cells(1, "B"),cells(.rows.count, "B"))
      for each c in range(cells(1, "B"), cells(1, .columns.count))
         Cells(r.row, c.column).Value = Trim(Cells(r.row, c.column).Value)
      next
    Next

  end with
End Sub


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top