VBA: sudden crash during macro execution

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I'm managing a lot of data with a complex macro.
At a certain point, Excel stops to work.

The message is:

Microsoft Excel has stopped working
Windows is checking for a solution to a problem


I have identified the part of code where the event happens.
lrt = 4586, the event happens beetween lrt = 2000 and lrt = 3000

Any suggestion?

Code:
Dim lrt As Long
lrt = Worksheets("Alpha").Cells(Rows.Count, "A").End(xlUp).Row

For Each cellnum In Range("BF2:BH" & lrt)
If cellnum.Offset(0, 3).Value = "Z" Then
     cellnum.Value = "0" & Trim(Str(cellnum))
  End If

Next
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What exactly are you trying to accomplish with this line?
Code:
     cellnum.Value = "0" & Trim(Str(cellnum))
It looks a little odd to me.

Also, suppressing calculations and screen updates while your code is running may help.
Place these lines at the beginning of your code:
Code:
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
and then these at the end of your code:
Code:
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
 
Upvote 0
What exactly are you trying to accomplish with this line?
Code:
     cellnum.Value = "0" & Trim(Str(cellnum))
It looks a little odd to me.

Also, suppressing calculations and screen updates while your code is running may help.
Place these lines at the beginning of your code:
Code:
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
and then these at the end of your code:
Code:
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

Same result.

With

Code:
cellnum.Value = "0" & Trim(Str(cellnum))

i had to add a 0 in front of telephone numbers (I receive a source without 0, but for landline it is needed).
 
Last edited:
Upvote 0
Without knowing the structure/size of your data, the rest of your VBA code, and the processing power of your computer, it is tough to say.
It looks like you are running out of resources. That part of the code you posted should not, by itself, cause a typical computer to crash.

It could be something like:
- a corrupt install of Excel
- corrupt workbook
- bad data
- inefficient VBA code
- too much other stuff going on that is hogging all the resources (in VBA or dependent formulas on the workbook)
- a computer without much processing power
 
Upvote 0
Without knowing the structure/size of your data, the rest of your VBA code, and the processing power of your computer, it is tough to say.
It looks like you are running out of resources. That part of the code you posted should not, by itself, cause a typical computer to crash.

It could be something like:
- a corrupt install of Excel
- corrupt workbook
- bad data
- inefficient VBA code
- too much other stuff going on that is hogging all the resources (in VBA or dependent formulas on the workbook)
- a computer without much processing power

Ok, the solution was inefficient VBA code.

Thank's.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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