Delete rows with current month or forward dated VBA

cameronb

Board Regular
Joined
Feb 13, 2009
Messages
146
I am trying to write code which will search a columns of data, in which anything dated in the current month or future dated would delete the entire row. Any suggestions, many thanks.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If you're deleting rows on the fly, always start from the bottom

Alternatively, you could use record macro, filter the data accordingly and delete the visible rows.

the first day of the current month can be found easily enough

=dateserial(year(now()),month(now()),1)
 
Upvote 0
Try

Code:
Sub deldate()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    With Range("A" & i)
        If .Value > Date Or Month(.Value) = Month(Date) Then Rows(i).Delete
    End With
Next i
End Sub
 
Upvote 0
Unfortunately excelr8r, it is part of a much larger VBA project.

I see the logic VoG, and nice formula, however, the screen crashes. I am not sure how to adapt this. I have tried with screenupdating = false, but no joy.
 
Upvote 0
Screen flashes for about 3 minutes, there are 10k rows of data. Then
an Error message appears runtime error 13, and highlights first start of If statement:

If .value > Date Or Month(.value) = Month(Date)
 
Upvote 0
Try

Code:
Sub deldate()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For i = LR To 1 Step -1
    With Range("A" & i)
        If IsDate(.Value) Then
            If .Value > Date Or Month(.Value) = Month(Date) Then Rows(i).Delete
        End If
    End With
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,479
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