Macro to Delete Dates in Col F which are Less than Date Specified in Col L

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have dates in Col F in format dd/mm/yyyy from row 2 onwards and a specified date in Col L1 in format mmm yyyy eg Nov 2020

Where the Date in Col L1 < the dates in Col F, I would like the rows in Col F drom row 2 owards to be deleted where L1 is less than those dates in Col F


See my code below

Code:
 Sub Delete_RowsBelowMinDate()

               
        With Sheet1.[A1].CurrentRegion
                .AutoFilter 6, "< L1"
                .Offset(1).EntireRow.Delete
                .AutoFilter
        End With

End Sub


Your assistance is most appreciated
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try this:
VBA Code:
Sub Delete_RowsBelowMinDate()
       With Sheet1.[A1].CurrentRegion
                .AutoFilter 6, "<" & [L1]
                .Offset(1).EntireRow.Delete
                .AutoFilter
        End With

End Sub
 
Upvote 0
The Date you write at L1 = Nov 2020 = 11/1/2020
When you run code the Rows have less than that date Deleted.
I test your file & don't see any problem.

AND One thing I realized:
Are you want Dates More (or Equal) than L1 Deleted Because you told

Where the Date in Col L1 < the dates in Col F

Rows Deleted. then you should change operator to Greater Than (">") or (">=").
 
Upvote 0
Hello Howard,

A slight modification to Maabadi's code should do the trick for you:-


VBA Code:
Sub Test()
      
          With Sheet1.[A1].CurrentRegion
                .AutoFilter 6, "<" & Format(Range("L1"), "MMM/YYYY")
                .Offset(1).EntireRow.Delete
                .AutoFilter
          End With
End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
Hi Mabaadi

I wanted dates less than the date in L1 to be deleted

The code provided by Vcoolio worked perfectly
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

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