Conditionally deleting of rows

If column E is not greater than 1% of column D and Column K  is lower than Column D  then keep all this type of row  and delete  rest row
If column E is not lower than 1% of column D and Column K  is greater than Column D  then keep all this type of row  and delete  rest row
Book1.xlsm
Sachin SinghAsked:
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.

Roy CoxGroup Finance ManagerCommented:
The easiest way would be to add a helper column then use AutoFilter. The helper column could be added with VBA and deleted if you want, or simply added and hidden. I'm off out for about an hour but I'll check back
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Since you didn't provide the expected output, I am not sure if I understood the delete criteria correctly.
Btw you may give this a try and see if you get the desired output.

Sub DeleteRows()
Dim ws As Worksheet
Dim lr As Long
Application.ScreenUpdating = False
Set ws = Sheets("Sheet2")
lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
ws.Range("N2:N" & lr).Formula = "=IF(OR(AND(NOT(E2>D2*1.01),K2<D2),AND(NOT(E2<D2*1.01),K2>D2)),"""",NA())"
On Error Resume Next
ws.Range("N2:N" & lr).SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete
ws.Columns("N").ClearContents
Application.ScreenUpdating = True
End Sub

Open in new window

In the attached, click the button called "Delete Rows" to run the code.
Sachin_Book1.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
Sachin SinghAuthor Commented:
Thnx Neeraj Sir and Roy Cox Sir for ur great support
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Sachin! ☺️
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 Office

From novice to tech pro — start learning today.