SimonHughes
Well-known Member
- Joined
- Sep 16, 2009
- Messages
- 507
- Office Version
- 365
- Platform
- Windows
I have a TRIM macro that fails if I apply it to many cells. I almost always use it to trim cells in a single column. It is fine when working on a limited number, say 60 but more than that and I get an error message.
Sub ATrim()
Dim R As Long, C As Long, vRng As Variant
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
vRng = Selection
For R = 1 To UBound(vRng, 1)
For C = 1 To UBound(vRng, 2)
vRng(R, C) = Trim(vRng(R, C))
Next
Next
Selection = vRng
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
I am using Excel 2010 on Win 7
Sub ATrim()
Dim R As Long, C As Long, vRng As Variant
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
vRng = Selection
For R = 1 To UBound(vRng, 1)
For C = 1 To UBound(vRng, 2)
vRng(R, C) = Trim(vRng(R, C))
Next
Next
Selection = vRng
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
I am using Excel 2010 on Win 7