Execution of VBA Causes Excel to become Unresponsive

talkinggoat

New Member
Joined
Feb 1, 2022
Messages
33
Office Version
  1. 365
Platform
  1. Windows
When I execute this script, it causes Excel to become unresponsive, assumingly while it operates, but it's not complicated. It locks up for about 10 minutes. This is on an 8-core i7 with 32gb of ram and an SSD. The sheet is a single column as text, with about 9400 rows. Is this normal or did I do something wrong?

VBA Code:
Sub TrimWhiteSpace ()
   Dim rng as Range
   Set rng as Selection
   For Each cell In rng
      cell.Value = Trim(cell)
   Next cell
End sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Do you have any formula that are updating based on those cells. Or do you have any code that runs on sheet calculate ?
 
Upvote 0
Do you have any formula that are updating based on those cells. Or do you have any code that runs on sheet calculate ?
I was just looking for an edit button to include this in my OP. No there are no formulas. It is the same 3 repeating numbers. I am also going to try disabling screen updating.
 
Upvote 0
Try setting calculations to manual just in case. But it doesn’t seem like it should take much longer than a couple of seconds
 
Upvote 0
I think the issue is the column being formatted as Text vs General. When it's text, Excel takes much longer.

Added:
VBA Code:
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
 
Upvote 0
I think the issue is the column being formatted as Text vs General. When it's text, Excel takes much longer.

Added:
VBA Code:
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Setting xlCalculationManual fixed the issue, whatever it was. There are no formulas in this column.
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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