date based delete

mani_singh

Well-known Member
Joined
Jul 24, 2007
Messages
583
hi i have a large set of data, with a data in column a & column e & some text in column F

i need macro to remove rows where the date in col a is earlier than 6 months before the date in column e & column f has the text "a/g or "g"

thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this

SAVE YOUR SHEET FIRST!!!!

Code:
Sub Test()
Dim LR, i
Dim x
LR = Cells(Rows.Count, "A").End(xlUp).Row
For i = LR To 1 Step -1
    If IsDate(Cells(i, "A")) And IsDate(Cells(i, "E")) Then
        If Cells(i, "A").Value < DateAdd("m", -6, Cells(i, "E").Value) Then
            If Cells(i, "F").Value = "a/g" Or Cells(i, "F").Value = "g" Then
                Rows(i).EntireRow.Delete
            End If
        End If
    End If
Next i
End Sub

Hope that helps..
 
Upvote 0
i've up this together

Code:
Sub runme()


LastRow = Sheets("data2").Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
For i = 3 To LastRow


 With Cells(i, "E")


If .Value > .Cells(i, "A") + Month(target) + 6 Then
If Cells(i, "F").Value = "A/G" Or Cells(i, "F").Value = "G" Then
Rows(i).EntireRow.Delete

End If
End If
End With
Next i

Application.ScreenUpdating = True

End Sub

it doesn't work butwhen i remove the if statement for looking for the R or A/R then it works!

any help?
 
Upvote 0
that's pretty far changed from the way I posted it...

Try this..
Code:
Sub Test()
Dim LR, i
Dim x
With Sheets("data2")
LR = .Cells(Rows.Count, "A").End(xlUp).Row
For i = LR To 1 Step -1
    If IsDate(.Cells(i, "A")) And IsDate(.Cells(i, "E")) Then
        If .Cells(i, "A").Value < DateAdd("m", -6, .Cells(i, "E").Value) Then
            If Ucase(.Cells(i, "F").Value) = "A/G" Or Ucase(.Cells(i, "F").Value) = "G" Then
                .Rows(i).EntireRow.Delete
            End If
        End If
    End If
Next i
End With
End Sub
 
Upvote 0
no change to the data!

e.g.test data
in col A = 1/1/08
in col e = 1/10/08
in col f = A/R

this should be deleted as the date in col a is OVER 6 month before date in col E and col F has a text string of "A/R"
 
Upvote 0
and col F has a text string of "A/R"
Your post (and the code you wrote) used A/G ?? which is it? Adjust the code accordingly..

Are the dates in Column A and E VALID Excel Dates ?
to verify, use these formulas in available columns ANYWHERE on your sheet..
=ISNUMBER(A1)
=ISNUMBER(E1)
Fill both down to the end of the data

Do they return TRUE or FALSE?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top