karmaimages
Board Regular
- Joined
- Oct 1, 2009
- Messages
- 112
- Office Version
- 365
- Platform
- Windows
I have the following macro in excel:
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?
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?