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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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