Trim Entire Column

B

Bob Zimski

Data was imported into a worksheet but the first column has the data padded
with spaces on the right of it. Is there a way to trim the data in the column
in one shot? The only way I know how would be the long way which is create
another column, do a trim on the data of the adjacent column, copy and paste
special as value the new column and then delete the original column.

There must be a better way in VBA.

Thanks
 
M

Mike

This is setup for column A
Sub trimData()
Dim rng As Range
Dim Cell As Range
Set rng = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
For Each Cell In rng
Cell.Value = Trim(Cell.Value)
Next Cell
End Sub
 
B

Bob Zimski

Just what the doctor ordered.
Thanks Mike

Mike said:
This is setup for column A
Sub trimData()
Dim rng As Range
Dim Cell As Range
Set rng = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
For Each Cell In rng
Cell.Value = Trim(Cell.Value)
Next Cell
End Sub
 

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

Excel 2013 Merge Data 2
Trim leading numbers 5
trim not working 2
Streamlining repetitive report 9
Excel Import XML into Excel 0
VBA Insert Into Specific Cell 0
VBA Type mismatch error 1
Trim function in macro 2

Top