ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   why is my loop so slow? (https://www.excelbanter.com/excel-programming/378696-why-my-loop-so-slow.html)

Buffyslay

why is my loop so slow?
 
what i need to do is delete any rows where col b = 0 or 2?


For conCat2 = 2 To iCountA
If ActiveCell.Value = 2 Then
ActiveCell.EntireRow.Delete
ElseIf ActiveCell.Value = 0 Then
ActiveCell.EntireRow.Delete

Else
ActiveCell.Offset(1, 0).Activate
End If
Next


TomHinkle

why is my loop so slow?
 
well, there are much better ways to do it (bottom)
but for starters, turn off screen updating before you run it.. that's one of
the most time intensive tasks for VBA is updating the screen.

application.screenupdating = false

after the loop turn it back on

application.screenupdating = true

that in itself will help you tremendously.


***
to streamline it, you could sort by column b first then you know all the
rows are together as well.
typically if I do something like that but want to preserve my original
order, I'll add an order column before any work is done..

"Buffyslay" wrote:

what i need to do is delete any rows where col b = 0 or 2?


For conCat2 = 2 To iCountA
If ActiveCell.Value = 2 Then
ActiveCell.EntireRow.Delete
ElseIf ActiveCell.Value = 0 Then
ActiveCell.EntireRow.Delete

Else
ActiveCell.Offset(1, 0).Activate
End If
Next




All times are GMT +1. The time now is 04:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com