The data that comes out of our corporate database always adds extra spaces to the cells so I wanted a macro that cleans the sheet up for me.
After searching the interwebs, I've managed to find this:
This works great although it always gives me a Run-time error '1004': Application-defined or object-defined error whenever one of the cells in the worksheet originally contained data like " =blabla" (i.e. a bunch of leading spaces with an equal sign).
I assume that the error is because after the Trim, excel is trying to do the sum (or other function) and this is causing the error.
Is there a way I can still trim my worksheet even with these occasional cells occuring?
After searching the interwebs, I've managed to find this:
Code:
Sub test()
Dim Cel As Range, Rng As Range
Set Rng = ActiveSheet.UsedRange
For Each Cel In Rng '' Causes Run-Time Error
If Len(Cel) > 0 Then Cel = Trim(Cel)
Next
End Sub
This works great although it always gives me a Run-time error '1004': Application-defined or object-defined error whenever one of the cells in the worksheet originally contained data like " =blabla" (i.e. a bunch of leading spaces with an equal sign).
I assume that the error is because after the Trim, excel is trying to do the sum (or other function) and this is causing the error.
Is there a way I can still trim my worksheet even with these occasional cells occuring?