Speeding up this once speedy code

Grizlore

Active Member
Joined
Aug 22, 2006
Messages
259
Could anyone suggest how I can speed up this code please?

This used to work really quickly, however on my new quicker 'laptop' it takes ages.

I can see in the bottom Excel bar it displaying Calculating (4 processers: x%). Which I have never seen before!

Anyway.. here is the code


Code:
Sub TrimEVERYTHING()

Dim rng, rngC, rngUnion As Range
 
Set rng = ActiveSheet.UsedRange
Set rngUnion = Nothing
 
For Each rngC In rng
    If Left(rngC.Formula, 1) <> "=" Then
        If rngUnion Is Nothing Then
            Set rngUnion = rngC
        Else
            Set rngUnion = Union(rngUnion, rngC)
        End If
    End If
Next rngC
 
For Each rngC In rngUnion
    rngC.Value = Evaluate("IF(ROW(" & rngC.Address & "),IF(COLUMN(" & rngC.Address & "),TRIM(" & rngC.Address & ")))")
Next rngC
 
MsgBox "TRIMMED"
End Sub

Any help in making this do exactly the same job, but be quicker would be appreciated
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this

Code:
Sub TrimEVERYTHING()

Dim rng As Range, rngC As Range, rngUnion As Range
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
Set rng = ActiveSheet.UsedRange
Set rngUnion = Nothing
 
For Each rngC In rng
    If Left(rngC.Formula, 1) <> "=" Then
        If rngUnion Is Nothing Then
            Set rngUnion = rngC
        Else
            Set rngUnion = Union(rngUnion, rngC)
        End If
    End If
Next rngC
 
For Each rngC In rngUnion
    rngC.Value = Evaluate("IF(ROW(" & rngC.Address & "),IF(COLUMN(" & rngC.Address & "),TRIM(" & rngC.Address & ")))")
Next rngC

With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
 
MsgBox "TRIMMED"
End Sub
 
Upvote 0
Thanks, now it is lightening fast

I see the changes, so... .Calculation = xlCalculationManual
was cycling through and slowing it all down?

It is the first time I have seen this.

Thanks again!

Much Appreciated !
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top