Delete Row when date in activecell doesn't meet the requierments
If I understand you correctly you want to delete the entire row if the date
in Col.G is greater than 1-1-2008 and Col.H is less than 12-31-2009, right?
This procedure will find the last row in Col.G and scan Col. G and Col.H till
row 2.
Option Explicit
Sub DeleteRows()
Dim lngLastRow As Long
Dim i As Long
lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "G").End(xlUp).Row
For i = lngLastRow To 2 Step -1
If Format(Cells(i, "G"), "m/dd/yyyy") "1/1/2008" Or _
Format(Cells(i, "H"), "m/dd/yyyy") < "12/31/2009" Then
Rows(i).EntireRow.Delete Shift:=xlUp
End If
Next i
End Sub
Hope this helps! If so, let me know and click "YES" below.
--
Cheers,
Ryan
"Basta1980" wrote:
I have a worksheet containing startdate in Column G and enddate in Column H
per user. I want VBA to test if a user doesn't meet the specifics (from an
inputbox), and then delete the entire row. So basically if user's contracted
has to be activated on or after 1-1-2008 and expired on or before 31-12-2009,
all users that do not meet those specifics get deleted. The date (i.e.
criteria) should be entered through an inputbox.
Thanks in advance
|