If the difference between column D and column G is equal or more than 3% or -3% then keep that data and delete the rest data

Sachin Singh
Sachin Singh used Ask the Experts™
on
If the difference between column D and column G is  equal  or more than 3% or -3% then keep that data and delete the rest data
HistoricalData.xlsb
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
is  equal  or more than 3% or -3%
Of which value column D or G?

Author

Commented:
Both
column D-G=should differ by 3% or -3%
3% and -3% means  if the value of d is great  then it will be 3% or the value of G  is greater then it will be -3%
Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
Does it work for you?

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("M2:M" & lr).Formula = "=IF(ABS(D2-G2)>D2*0.03,"""",NA())"
On Error Resume Next
ws.Range("M2:M" & lr).SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete
ws.Columns("M").Clear
Application.ScreenUpdating = True
End Sub

Open in new window

Author

Commented:
Thnx Neeraj  sir for ur great support
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
Welcome Sachin!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial