Del row based on cell value

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
I would like to search column "D" and whenever it finds the word "Gone" delete that row.
Why does this not work?
It runs but does nothing.

Sub DeleteOnD()


'Application.ScreenUpdating = False

For LR = Range("D" & Rows.Count).End(xlUp).Row To 2 Step -1
If Range("D" & LR).Value = "Gone" Then Rows(LR).EntireRow.Delete
Next LR


'Application.ScreenUpdating = True
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Are the entries in column D EXACTLY equal to "Gone", or is "Gone" just one word in a longer string?
 
Upvote 0
Hello wmtsub,

I've just tested your code a few times and it works just fine for me. Is it definitely Column D in which the criteria "Gone" is placed?

If it still doesn't work for you, try the following method:-


Code:
Sub DeleteIt()

Application.ScreenUpdating = False

With Sheet1.[A1].CurrentRegion   '---->Change Sheet1 to your sheet name or actual sheet code.
           .AutoFilter 4, "Gone"
           .Offset(1).EntireRow.Delete
           .AutoFilter
End With


Application.ScreenUpdating = True

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
i would like to search column "d" and whenever it finds the word "gone" delete that row.
Why does this not work?
It runs but does nothing.

Sub deleteond()


'application.screenupdating = false

for lr = range("d" & rows.count).end(xlup).row to 2 step -1
if range("d" & lr).value = "gone" then rows(lr).entirerow.delete
next lr


'application.screenupdating = true
end sub

it could be a case of .. "case sensitive"
 
Upvote 0
Use this
Code:
If LCase(Range("D" & lr).Value) = "gone" Then Rows(lr).EntireRow.Delete
 
Upvote 0
Hello wmtsub,

In my code in post #4 , cases are irrelevant as using autofilter won't discriminate.

With the code in your opening post, place this:-

Code:
Option Compare Text

directly above your sub name (Sub DeleteOnD())

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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