Trim function in VBA

  • Thread starter Thread starter molavi111
  • Start date Start date
M

molavi111

Hi,

I would like to know how to write a macro that selects all rows/column
on a worksheet and perform the trim function (both right and left
within each cell.

thanks a lot!
 
Try this:

Public Sub TrimItAll()

For Each objC In Application.Selection

objC.Value = Trim(objC.Value)

Next

End Sub
 
Sub doATrim()
for each cell in Activesheet.UsedRange.specialCells(xlconstants,
xlTextValues)
cell.Value = trim(cell.Value)
Next
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

Back
Top