Link to home
Start Free TrialLog in
Avatar of Flora Edwards
Flora EdwardsFlag for Sweden

asked on

VBA to trim leading and trailing spaces in all sheets of active workbook.

I had this question after viewing VBA how to delete all objects regardless of its type from all worksheets in workbook.

Rgonzo and Norie has helped me with this code. now i want to add something so that it quickly cleans up the leading and trailing spaces with Character 160 and character 10
Sub Macro()
For Each sh In ActiveWorkbook.Worksheets
    With sh.Cells.Font
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
    End With
    With sh.Cells.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    For Each obj In sh.Shapes
            obj.Delete
        Next obj
Next
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Flora Edwards

ASKER

Wonderful! you are the best