Delete an entire row based on a condition value in one of the columns in the row

I have a row of data/  in one cell i set up a match condition, so if it is equal to zero i want to delete the row and keep deleting until all rows that have dont match are deleted and subsequent matching rows move up to line up consecutively.
inee leeAsked:
Who is Participating?

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

x
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.

Dorababu MSenior Software EngineerCommented:
Try this
Sub DeleteRow()
    Dim lRow As Long
    Dim iCntr As Long
    lRow = 390
    For iCntr = lRow To 1 Step -1
        If Cells(iCntr, 5).Value = "none" Then // change this condition as per need
            Rows(iCntr).Delete
        End If
    Next
    End Sub

Open in new window

inee leeAuthor Commented:
Sorry I'm new to using VBA.  So suppose i want to loop thru based on a column F values = 0 than delete.  The code you provided in RED,  i put value = 0 there but how do i set the column there?

thanks
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
So suppose i want to loop thru based on a column F values = 0 than delete.
you can customize what Dorababu posted to something like this:

Sub test()
    Dim LastRow As Integer
    
    If MsgBox("Are you sure want to delete the rows?", vbExclamation + vbYesNo, "Delete rows?") = vbYes Then
        LastRow = Cells(Rows.Count, "F").End(xlUp).Row
        For i = LastRow To 2 Step -1 'Assuming got header
            If Cells(i, "F") = 0 Then
                Rows(i).Delete
            End If
        Next
    End If
End Sub

Open in new window

29077749.xlsm

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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

inee leeAuthor Commented:
Thank you will give this a go!
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
any test results so far?
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
as proposed
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.