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?
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

0
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
0
Ryan ChongCommented:
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
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

inee leeAuthor Commented:
Thank you will give this a go!
0
Ryan ChongCommented:
any test results so far?
0
Ryan ChongCommented:
as proposed
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.