Applying the Excel's Trim Function on the Entire Workbook.

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hey Excel Gurus,

I have a large data with multiple worksheets. Please my requirement this time is for a vba code that performs trimming on the existing data present in all worksheets of my workbook.

For example if text is (without the quotation marks):

" abc def "

the code runs and check for data cells on each sheet and voila...

"abc def"

Thank you and much appreciation.
 
Try this mod to Yongle' code
Code:
Sub Trim_All_Sheets()
    Dim ws As Worksheet, cel As Range
        With Application
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
                For Each ws In ThisWorkbook.Sheets
                    For Each cel In ws.Cells.SpecialCells(xlCellTypeConstants)
                        If Not IsError(cel) Then cel.Value = WorksheetFunction.Trim(cel.Value)
                    Next cel
                Next ws
            .Calculation = xlCalculationAutomatic
    End With
End Sub
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top