Delete Rows

Hello

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.
macone1976Asked:
Who is Participating?
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:
Hello,
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

-FA
0
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

0
macone1976Author 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
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

Open in new window

0

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.
0
macone1976Author Commented:
Thank You
0
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
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.