Looping too many rows (+500,000)

Axel

New Member
Joined
Aug 25, 2008
Messages
13
Hi, im working with to many rows (> 500,000) and several sheets or workbooks, using VBA which is the better and faster way to:

a) Loop rows in sheet 1 and add a value that i have to find in sheet 2 or other workbook. ( im using while ... loop with a match function to find the row of the value then with a specific column retrieve the value to add it )


b) Delete about 50,000 rows that match a criteria like empty cells in a columna A. (im using a filter and delete entire rows)

About 5 minutes to complete the process.. how can i reduce it?

Thanks!

:confused:
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
hello

You should show the relevant code, then if you have not yet disabled events such as:

Code:
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
and restoring it at the end of the cycle:

Code:
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
 
Upvote 0
Thanks for your reply ISY, i use your code but is almost the same time :(, the code im using:

a) To lookup and add a value

Code:
   i = 0
   Do While Cells(5 + i, 1).Value <> ""
     j = Application.WorksheetFunction.Match(Cells(5 + i, 5).Value, Range("rgColumnDist"), 0)
     Cells(5 + i, 19).Value = Sheets("Data").Cells(j, 11).Value
     i = i + 1
   Loop


b) To delete rows

Code:
   ActiveSheet.Range("$A$4:$Q$1000000").AutoFilter Field:=1, Criteria1:="="
   Range("B5").Select
   Do
      ActiveCell.Offset(1, 0).Select
   Loop Until Rows(ActiveCell.Row).Hidden = False
   Range(Selection, Selection.End(xlDown)).Select
   Selection.EntireRow.Delete
Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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