ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trim function in VBA (https://www.excelbanter.com/excel-programming/310916-trim-function-vba.html)

molavi111

Trim function in VBA
 

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!

--
molavi11
-----------------------------------------------------------------------
molavi111's Profile: http://www.excelforum.com/member.php...fo&userid=1461
View this thread: http://www.excelforum.com/showthread.php?threadid=26244


MDW

Trim function in VBA
 
Actually, I think you need Application.Selection.Cells

my bad

"molavi111" wrote:


Hi,

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

thanks a lot!!


--
molavi111
------------------------------------------------------------------------
molavi111's Profile: http://www.excelforum.com/member.php...o&userid=14618
View this thread: http://www.excelforum.com/showthread...hreadid=262446



MDW

Trim function in VBA
 
Try this:

Public Sub TrimItAll()

For Each objC In Application.Selection

objC.Value = Trim(objC.Value)

Next

End Sub



"molavi111" wrote:


Hi,

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

thanks a lot!!


--
molavi111
------------------------------------------------------------------------
molavi111's Profile: http://www.excelforum.com/member.php...o&userid=14618
View this thread: http://www.excelforum.com/showthread...hreadid=262446



Tom Ogilvy

Trim function in VBA
 
Sub doATrim()
for each cell in Activesheet.UsedRange.specialCells(xlconstants,
xlTextValues)
cell.Value = trim(cell.Value)
Next
End Sub

--
Regards,
Tom Ogilvy


"molavi111" wrote in message
...

Hi,

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

thanks a lot!!


--
molavi111
------------------------------------------------------------------------
molavi111's Profile:

http://www.excelforum.com/member.php...o&userid=14618
View this thread: http://www.excelforum.com/showthread...hreadid=262446





All times are GMT +1. The time now is 05:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com