Hello,
I'm using Excel 2013. I was running the macro below to trim all excess spaces out of cells. The macro was running fine until today. Now, I get the Runtime Error 13 Type Mismatch. I'm not sure why. Is there a more reliable code you could recommend? Thanks.
I'm using Excel 2013. I was running the macro below to trim all excess spaces out of cells. The macro was running fine until today. Now, I get the Runtime Error 13 Type Mismatch. I'm not sure why. Is there a more reliable code you could recommend? Thanks.
Code:
Sub TrimXcessSpaces()
'On Error Resume Next
'I could un-comment the line above to "solve" the problem but I'm not sure if that would be a good idea.
Dim cl As Variant
With ActiveSheet.UsedRange
For Each cl In ActiveSheet.UsedRange
If Len(cl) > Len(WorksheetFunction.Trim(cl)) Then 'this part is yellow
cl.Value = WorksheetFunction.Trim(cl)
End If
Next cl
End With
End Sub