Macro freezing worksheet

tarmand

Board Regular
Joined
Jul 11, 2002
Messages
196
I have about ten worksheets that I update every month. They are all the same but for different projects. They all have the same 7 macros in them. They have worked fine for about a year, but now when I run one of the macros, it freezes Excel for about 15-20 minutes. When I look at the task manager, it shows that Excel is running so I just wait and it always eventually unfreezes. Any ideas as to what is wrong? This happens when I run that macro on all of the worksheets.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
50,644
Office Version
  1. 365
Platform
  1. Windows
tarmand

Would it be possible to post the macro code on the board?
 

tarmand

Board Regular
Joined
Jul 11, 2002
Messages
196
Here it is:

Sub Datechange()
Range("$b$2:$b$65536").Select
For Each c In Selection
c.Value = Right(c.Value, 4) & "-" & Mid(c.Value, 2, 2)
Next c
End Sub
 

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,547
Hi tarmand,

can I ask why it's necessary to fill values in column B for so many cells? Surely the required amount of entries is going to be less than 65,535 cells worth, isn't it?

When doing a loop like this you may wish to switch off calculation before processing and reinstate it afterwards. See the Application.Calculation command in VBA help.
 

tarmand

Board Regular
Joined
Jul 11, 2002
Messages
196

ADVERTISEMENT

Glenn,

I just did it to the end of the worksheet since I never know how many rows I will have. It is usually less than 10,000 rows so I could change it to that. Do you think that would help? What confuses me is that it has always worked in a matter of seconds in the past and just in the last two days has begun to give me problems.

Thanks,
Tammie
 

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
Give this code change a try. It's dynamic and knows what the last populated cell in Column B is, so you don't do the entire column.

Code:
Sub Datechange() 
Dim c as range

For Each c In range("B2",range("B"&activesheet.rows.count).end(xlup))
c.Value = Right(c.Value, 4) & "-" & Mid(c.Value, 2, 2) 
Next c 
End Sub

As far as what is cause the delay now, did you add new formula's, maybe a filter? These kind of things may cause a slow down.

HTH
Cal
 

tarmand

Board Regular
Joined
Jul 11, 2002
Messages
196
Wow, that worked. It ran the macro in less than a second. I don't think I changed anything in the reports, but others do have access to the reports and I don't know what they may have done.

Thanks!
 

Forum statistics

Threads
1,141,599
Messages
5,707,311
Members
421,502
Latest member
PULBAG

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
Top