Macro crashing due to "out of Memory"

karmaimages

Board Regular
Joined
Oct 1, 2009
Messages
112
Office Version
  1. 365
Platform
  1. Windows
I have the following macro in excel:

Code:
Sub Analyze()
'   , ' ; - !
LR = Application.WorksheetFunction.CountA(Sheets("Address Original").Range("A:A"))
k = 2
Sheets("Errors").Range("A2:N1000000").ClearContents
For i = 2 To LR
c = ""
For j = 1 To 13
c1 = 0
c2 = 0
c3 = 0
c4 = 0
c5 = 0
c6 = 0
c7 = 0
c8 = 0
c9 = 0
c1 = InStr(Sheets("Address Original").Cells(i, j), ",")
c2 = InStr(Sheets("Address Original").Cells(i, j), "'")
c3 = InStr(Sheets("Address Original").Cells(i, j), ";")
c4 = InStr(Sheets("Address Original").Cells(i, j), "-")
c5 = InStr(Sheets("Address Original").Cells(i, j), "!")
c6 = InStr(Sheets("Address Original").Cells(i, j), "&")
c7 = InStr(Sheets("Address Original").Cells(i, j), "/")
c8 = InStr(Sheets("Address Original").Cells(i, j), "\")
c8 = InStr(Sheets("Address Original").Cells(i, j), "*")
If c1 > 0 Then c = c & ","
If c2 > 0 Then c = c & "'"
If c3 > 0 Then c = c & ";"
If c4 > 0 Then c = c & "-"
If c5 > 0 Then c = c & "!"
If c6 > 0 Then c = c & "&"
If c7 > 0 Then c = c & "/"
If c8 > 0 Then c = c & "\"
If c9 > 0 Then c = c & "*"
Next j
If c <> "" Then
Sheets("Errors").Rows(k).Value = Sheets("Address Original").Rows(i).Value
Sheets("Errors").Range("N" & k).Value = c
k = k + 1
Sheets("Address Original").Rows(i).Delete
End If
Next i

'
End Sub

It's analysing around 500,000 rows of data in excel, but it's causing excel to crash as it runs out of memory. Does anyone have any suggestions on how to stop this happening?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Put Option Explicit at the top. I'm guessing that it's the deleting rows that's causing the crash. HTH. Dave
 
Upvote 0
Put Option Explicit at the top. I'm guessing that it's the deleting rows that's causing the crash. HTH. Dave


Thanks for the reply, when I add OE, it now errors with a compile error, Variable not defined and LR is highlighted.
 
Upvote 0
Option Explicit, simply forces you to declare all your variables & is strongly recommended.
As for your problem, there could be a number of reasons.
The best thing, would be for you to explain what you are trying to achieve. That way, one of the members here, may be able to come up with a solution that works.
 
Upvote 0
I'm guessing if U turn off the auto document recovery feature that your macro will stop crashing. Also consider turning off screen updating and automatic calculations at the start of the code and then turning them back on at the end of your code. This will greatly reduce the time it takes to run your code and/or stop the crashes. Good luck. Dave
 
Upvote 0
I'm guessing if U turn off the auto document recovery feature that your macro will stop crashing. Also consider turning off screen updating and automatic calculations at the start of the code and then turning them back on at the end of your code. This will greatly reduce the time it takes to run your code and/or stop the crashes. Good luck. Dave

Hi Dave,

Unfortunately not it still crashed when it gets to just over 1gb of ram. Do you think there is a better way to have this macro run.

It's searching for errors in addresses that contain the characters above then moving the row if any of them appear and putting the characters it finds in column N on the error sheet.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
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