Delete Rows


Need a macro to go to sheet "VAS" and search in column F, if the word "expired" appears, then delete that entire row and move up the data below it.
macone1976Incident ResponderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Farzad AkbarnejadDeveloperCommented:
Create a macro and write the following lines of code in your macro:
Dim FindRow As Range
Set FindRow = Me.Sheets("VAS").Range("F:F").Find(What:="expired", LookIn:=xlValues)
Rows(FindRow.Row).Delete (True)

Open in new window

Karthik RamachandranCommented:
Try this.
Sub DeleteRowsWithExpired()
    MySheet = ActiveWorkbook.Worksheets("VAS")
    Last = Cells(Rows.Count, "F").End(xlUp).Row
    For i = Last To 1 Step -1
        If (Cells(i, "F").Value) = "expired" Then
            Cells(i, "A").EntireRow.Delete
        End If
    Next i
End Sub

Open in new window

macone1976Incident ResponderAuthor Commented:
Thanks for the code Farzad, however it is only deleting just the first expired row, there are more than just one row with Expired on it.  how do i get them all deleted
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

macone1976Incident ResponderAuthor Commented:
Karthik, I am getting a runtime error on the second line, it says object doesnt support this property
Farzad AkbarnejadDeveloperCommented:
Simply write:
Sub DelR()
On Error GoTo finish
Dim FindRow As Range
    Set FindRow = Me.Sheets("VAS").Range("F:F").Find(What:="expired", LookIn:=xlValues)
    Rows(FindRow.Row).Delete (True)
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Farzad AkbarnejadDeveloperCommented:
The above code delete all rows with "expired" word with no error.
macone1976Incident ResponderAuthor Commented:
Thank You
Roy CoxGroup Finance ManagerCommented:
The best way to code this would be to use AutoFilter. Automating AutoFilter will be much faster especially on large data sets
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.