Pat_The_Bat
Board Regular
- Joined
- Jul 12, 2018
- Messages
- 83
Trying to delete any rows that have a date prior to the 1st day of the current month. When I debug.print my variable MTD it gives the date 8/1/2018, but then when I filter and delete rows it goes haywire. Any advice?
Code:
Sub MTDapps()
With Sheets("Table")
Rows.Sort Range("J2"), order1:=xlDescending, Header:=xlYes
End With
Dim MySheet As Worksheet
Dim LastRow As Long, LastCol As Long
Dim MyRange As Range
Application.DisplayAlerts = False
Dim m As Integer
Dim y As Integer
Dim MTD As Date
m = month(Now)
y = year(Now)
MTD = m & "/1/" & y
Debug.Print m
Debug.Print y
Debug.Print MTD
Set MySheet = ThisWorkbook.Worksheets("Table")
With MySheet
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
LastCol = .Range("A" & .Columns.Count).End(xlToLeft).Column
Set MyRange = .Range(.Cells(1, 1), .Cells(LastRow, LastCol))
End With
With MyRange
.AutoFilter Field:=1, Criteria1:="<" & MTD
'.SpecialCells(xlCellTypeVisible).Offset(1, 0).Resize(.Rows.Count).Rows.Delete
End With
End Sub