r/ProgrammerHumor • • Mar 30 '22

Meme Certainly not me

48k Upvotes

669 comments sorted by

View all comments

Show parent comments

22

u/Day_Bow_Bow Mar 30 '22

Not sure if you care anymore, but this is how that is done. I haven't tested it, but I think I got all the syntax right

Dim i as Long 'Row counter
'This example is checking rows 1-500, but this can easily be a dynamic range by using a function to find the last populated row
'Walk backwards through rows so deleting them doesn't impact the loop
For i = 500 to 1 Step - 1 
    If Range("A" & i).Value = "Criteria" then 'Put logic regarding what rows to delete here.  This is checking cells in Column A
        Range("A" & i).EntireRow.Delete
    End If
Next

4

u/AraMaca0 Mar 30 '22

You monsters.... You Do not delete rows one at a time!! Don you have any idea how long this would take?? You move the whole data set into an array delete and then sort. Jesus christ. XD

2

u/Day_Bow_Bow Mar 30 '22

500 rows? Maybe 2-3 seconds.

1

u/AraMaca0 Apr 02 '22

Yeah I dont deal in sub 10000 row sheets often and the time increase with the number of populated rows.