Modify VBA to Exclude Dates Prior to Today

Justinian

Well-known Member
Joined
Aug 9, 2009
Messages
1,557
Office Version
  1. 365
Platform
  1. Windows
I use the following code to remove buildings in my property that are less than 33. So building 9-32 would be removed from the spreadsheet.

I would like to know how to modify this code so dates before today are also removed.

Any ideas?

Sub Remove_Gardens()
Dim i As Long, n As Long
Dim va, fm

' Remove garden units from this worksheet
Sheets("Make Ready Board").Activate
n = Cells(Rows.Count, "A").End(xlUp).Row
With Range("A1:F" & n)

.Sort Key1:=[A1], Order1:=xlAscending, Header:=xlYes

va = .Value
For i = 2 To n
If CStr(Left(va(i, 1), 2)) >= "33" Then Exit For
Next

If i > 2 Then
Rows("2:" & i - 1).Delete
Else
MsgBox "Can't find Unit with number below 33xx"
End If
.Sort Key1:=[E1], Order1:=xlAscending, Header:=xlYes
fm = Application.Match(CLng(CDate(Date)), Range("E1:E" & n), 0)

If IsNumeric(fm) Then
If fm > 2 Then Rows("2:" & fm - 1).Delete
Else
fm = Application.Match(CLng(CDate(Date)), Range("E1:E" & n), 1)
If IsNumeric(fm) Then Rows("2:" & fm).Delete
End If

End With

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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