Macro randomly fails; possibly with large volume of line items

cdrobinson83

New Member
Joined
May 3, 2021
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hello,

So I created this macro to sift through data and produce some weekly metrics. It works if I only do 1 week at a time (5 days) which is generally around 1,700 lines of raw data. It runs quickly and smoothly. But if I try for more data, it chokes and freezes without an error message. It seems strange that it would fail since it runs quickly in other cases. So I'm wondering if it's not actually related to the number of items to sift through.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Sub CLEANUP()



'

' Delete Montreal equities that are not from early exercise

'



'

Sheets("COPY").Select

Range("A1").Select



ActiveSheet.Range("$A$1:$Z$10000").RemoveDuplicates Columns:=Array(3, 7, 8, 9, 10, _

13, 15, 19), Header:=xlYes

Range("A1").Select



Columns("T:T").Select

Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Range("T1").Select

ActiveCell.FormulaR1C1 = "EARLY"

Range("A1").Select



R = 2

C = 1



Do Until Cells(R, C) = ""



If Range("O" & R) = "1" And Range("N" & R) > Range("S" & R) Then

Cells(R, C + 19) = "Y"

Else

Cells(R, C + 19) = "N"



End If



If Range("H" & R) = "CB" And Range("O" & R) = "1" Then

Cells(R, C).EntireRow.Delete

ElseIf Range("H" & R) = "CB" And Range("N" & R) < Range("S" & R) Then

Cells(R, C).EntireRow.Delete

ElseIf Range("H" & R) = "CB" And Range("O" & R) = "2" Then

Cells(R, C + 19) = "Y"

Else

R = R + 1



End If



Loop



Sheets("COPY").Select

Cells.Select

Selection.Copy

Sheets("PASTE").Select

ActiveSheet.Paste

Range("A1").Select



ActiveWorkbook.RefreshAll



Sheets("PASTE").Select

Range("A1").Select

Sheets("COPY").Select

Range("A1").Select

Sheets("MACRO").Select

Range("A1").Select





End Sub
VBA Code:
 
Upvote 0
Maybe if you explain in a concise manner what you want to achieve, someone will show you a code that works.

BTW, selecting is very seldom required, the last 13 lines you have it 10 times, and slows down computing tremendously.
 
Upvote 0
I was able to figure it out. Part of it was some of the criteria clashing with other instances. So I was able to amend the actual raw data I was consuming to eliminate some of the unwanted records to start out with. After that, I was able to eliminate the processing error by just tweaking the original steps. I also removed many of the “select” commands as you pointed out ;)
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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