more efficient than a loop?

Status
Not open for further replies.

TinaP

Well-known Member
Joined
Jan 26, 2005
Messages
528
Hi folks!

I have a list of records, 12000+ records long, where I must remove any records with a dollar field under 3000. I've automated the importing of the data as well as most of the other tasks related to generating the report using VBA. Currently, I'm looping through every record and deleting records that are under 3000, then sorting. It takes more than 5 minutes just for this segment of code. Can anyone help me make the code more efficient?

Code:
Private Sub Remove_Trans_Under_3000()
Dim Cell As Range

  Application.Calculation = xlManual
  Application.ScreenUpdating = False
  Range("L2") = "=SUMPRODUCT(--(DateRange=A2),--(PurchaserRange=G2),--(VoidRange<>""Y""),AmtRange)"
  Range("HelperRange").FillDown
  Calculate
  For Each Cell In Range("HelperRange")
    If Cell < 3000 Then Cell.EntireRow.Clear
  Next Cell
  Range("L1").EntireColumn.Delete
  Cells.Select
  Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
  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"
Status
Not open for further replies.

Forum statistics

Threads
1,222,691
Messages
6,167,670
Members
452,131
Latest member
MichelleH77

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