Slow Function

W

WhytheQ

I've tried the below function over a range of 6000 cells.

'======================================
Private Function TrimAll(myTrimArea As Range)
Dim cell
For Each cell In myTrimArea.Cells
cell.Value = Trim(cell.Value)
Next cell
End Function
'======================================

.....it's very slow.
What is wrong with my code ?

Any help greatly appreciated
J
 
G

Guest

This should help considerably, it turns off all processing, does the work,
and then calculates once instead of thousands of times.

Private Function TrimAll(myTrimArea As Range)
Dim cell
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

For Each cell In myTrimArea.Cells
cell.Value = Trim(cell.Value)
Next cell
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top