Fastest way to delete rows based on cell

shadow12345

Well-known Member
Joined
May 10, 2004
Messages
1,238
Hi all,

I have a sheet with over 50,000 rows. I am looking for the fastest way to check if column M on that row value has a value of "S". If it does then delete the entire row it.

This is the first stage of a macro, i have tried looping though it but it takes for ever! Any other ideas?

Its a header row then just row after row of data (if it helps M with always be either B -- S -- or blank)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You are welcome!

Just for curiosity, how much time to do the job in 50000 rows?

M.
 
Upvote 0
was taking about 15 mins but that running it over a terminal server.... on a stand alone machine it was only 3 or 4 minutes.
 
Upvote 0
yeah it was the terminal server that was killing me... every time i ran it to test i had to wait ages!

Now its only maybe 5 mins on the t server (i haven't test the stand alone yet)
 
Upvote 0
Please, when you test it on the stand-alone computer tell me something about.

M.
 
Upvote 0
Hi all,

I have a sheet with over 50,000 rows. I am looking for the fastest way to check if column M on that row value has a value of "S". If it does then delete the entire row it.
You might also like to try this. Maybe fast enough for your purpose.
Code:
Sub deleterows()
t = Timer
Dim lr&, lc&, colm, u(), k&, x&
lr = Cells.Find("*", after:=[a1], searchorder:=xlByRows, _
        searchdirection:=xlPrevious).Row
lc = Cells.Find("*", after:=[a1], searchorder:=xlByColumns, _
        searchdirection:=xlPrevious).Column
colm = [m1].Resize(lr)
ReDim u(1 To lr, 1 To 1)
For k = 1 To lr
    If colm(k, 1) = "S" Then x = x + 1: u(k, 1) = 1
Next k
Cells(1, lc + 1).Resize(lr) = u
[a1].Resize(lr, lc + 1).Sort Cells(1, lc + 1), 1, Header:=xlYes
[a2].Resize(x, lc + 1).Delete xlUp
MsgBox "Code took " & Format(Timer - t, "0.000 secs")
End Sub
 
Upvote 0
What if in addition to "S", you want to delete a row if that cell contains "T", "U", or "V" as well?
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

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