Macro - Delete row based on date

ketchupthief

New Member
Joined
Feb 26, 2011
Messages
2
Hello all,

I am looking to add a macro in to delete all rows with dates above a specific date (i.e. delete all rows with a date above cell A12). I'm using Excel 2003. Any advice?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Are the dates in increasing /decreasing order, or are they distributed some other way e.g randomly?
 
Upvote 0
The Macro is already set up to sort in descending order (Most current date to oldest date). I'm looking to delete all rows with dates in column B less than 1/1/2011. However, this date will be changing on a montly basis.
 
Upvote 0
Hi
This will do the trick, if the data is in column "B". However, there are a couple of questions.
What if the date is = to A12 ??
Does the column of dates run past A12, eg, B5 to B20. If so, that row needs to be skipped or the data needs to be relocated to a better location
Code:
Sub datedel()
Dim lr As Long, r As Long
lr = Range("B" & Rows.Count).End(xlUp).Row
    For r = lr To 13 Step -1
        If Range("B" & r).Value > Range("A12").value Then Rows(r).Delete
    Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,712
Members
452,939
Latest member
WCrawford

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