View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jef Gorbach Jef Gorbach is offline
external usenet poster
 
Posts: 59
Default Delete rows between two dates

consider these:

'use autofilter to hide the desired dates to keep then delete all visible
rows
'change cells(finalrow,7) to however many columns you have
'change field:=1 to whichever is your date column
finalrow = range("A65536").end(xlup).row
BOM = "<" & beforenow
EOM = "" & beforenow+30
With Range(Cells(1, 1), Cells(finalrow, 7)) 'change 7 to however many
columns you have
..AutoFilter Field:=1, Criteria1:=BOM, Operator:=xlOr, Criteria2:=EOM
..Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count) _
..SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
ActiveSheet.AutoFilterMode = False 'turn off autofilter

'now remove rows with col(A)=perm and col(c)=client enddate
for lrow = finalrow to 2 step -1
if trim(lcase(range("A"&lrow).value))="client enddate" _
and trim(lcase(range("C"&lrow).value))="perm" _
then rows.delete
next lrow
===============================

' This will delete each row with the Values in Columns A and C, case
insensitive.
ElseIf Trim(LCase(.Cells(Lrow, "C").Value)) = "perm" And _
.Cells(Lrow, "A").Value = "Client EndDate" Then .Rows(Lrow).Delete
'+++++++++++++++++++++++++++++++++++++++++
End If



=============

"jocker" wrote in message
. nl...
I am using this code to delete rows which contain "perm" and "Client
EndDate" .
I also wish to delete rows before now and after now + 30 days.
I've tried all sorts of combinations without success. Can somwone help a
relative newcomer to VBA

Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "A").Value) Then ' Do nothing
'++++++++++++++++++++++
' This will delete each row with the Values in Columns A and C, case
insensitive.
ElseIf Trim(LCase(.Cells(Lrow, "C").Value)) = "perm" And _
.Cells(Lrow, "A").Value = "Client EndDate" Then .Rows(Lrow).Delete
'+++++++++++++++++++++++++++++++++++++++++
End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With