VBA: Excel crashes with a bigger amount of data

Nelson78

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

I have a problem with one of my macro: with a bigger amount of data then usual, Excel crashes without reporting the type of error.

https://imgur.com/a/gGkwECB

I have isolated the part of the code which causes the matter, and it should be the following.

In this case the amount of data is:
lrt (number of rows) = 2731
populated columns = 32

If I divide the data by 3 (about 1000 rows), the macro works correctly.

Thank you for any suggestion.



Code:
Sub add_zero()

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

Dim lrt As Long
lrt = Worksheets("Records").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


    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hello everybody.

I have a problem with one of my macro: with a bigger amount of data then usual, Excel crashes without reporting the type of error.

https://imgur.com/a/gGkwECB


I have isolated the part of the code which causes the matter, and it should be the following.

In this case the amount of data is:
lrt (number of rows) = 2731
populated columns = 32

If I divide the data by 3 (about 1000 rows), the macro works correctly.

Thank you for any suggestion.



Code:
Sub add_zero()

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

Dim lrt As Long
lrt = Worksheets("Records").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


    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub

May be I can proceed with blocks of 100.
Or not?
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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