How to speed up a macro that removes blank spaces?

I have close to 100,000 cells that needs blank spaces removed my current code I use takes a long time is there a faster way?

Here is my code that I use...

Dim Rng As Range
    For Each Rng In Intersect(ActiveSheet.UsedRange.Cells, ActiveSheet.Range("O:Z"))
    Rng.Value = Application.WorksheetFunction.Trim(Rng.Value)
    Next

Thanks,
Jimi
Jimi ShermanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saqib Husain, SyedEngineerCommented:
Try


Dim Rng As Range
application.calculation=xlcalculationmanual
    For Each Rng In Intersect(ActiveSheet.UsedRange.Cells, ActiveSheet.Range("O:Z"))
    Rng.Value = Application.WorksheetFunction.Trim(Rng.Value)
    Next
application.calculation=xlcalculationautomatic
0
nutschCommented:
From Saqib's example, I'd add
application.screenupdating=false
at the beginning and
application.screenupdating=true
at the end.
0
Jimi ShermanAuthor Commented:
I am sorry I did not included that in my code that I posted but I used both of those at the beginning and the end of the whole macro process.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Saqib Husain, SyedEngineerCommented:
Then try something like

Dim trng As Variant, strg As Variant
trng = Intersect(ActiveSheet.UsedRange.Cells, ActiveSheet.Range("O:Z")).Value
    For Each strg In trng
    strg = Application.WorksheetFunction.Trim(strg)
    Next
0
Jimi ShermanAuthor Commented:
Hi ssaqibh,
That did not remove a lot of the blank spaces.
0
Saqib Husain, SyedEngineerCommented:
Can you please upload a small sample for experimenting?
0
Jimi ShermanAuthor Commented:
0
Saqib Husain, SyedEngineerCommented:
I could not get that to work either :(

So try this

Dim ws As Worksheet, tws As Worksheet
Set ws = ActiveSheet
Set tws = Worksheets.Add
tws.Range(Intersect(ws.UsedRange.Cells, ws.Range("O:Z")).Address).FormulaR1C1 = "=trim('" & ws.Name & "'!rc)"
ws.Range(Intersect(ws.UsedRange.Cells, ws.Range("O:Z")).Address).Value = tws.Range(Intersect(ws.UsedRange.Cells, ws.Range("O:Z")).Address).Value
tws.Delete
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimi ShermanAuthor Commented:
That is super FAST!
Thank you!
Jimi
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.