Macro to filter dates and tdelete those rows

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have dates in Col F on sheet2


I have manually filtered the dates prior to 01/10/2017 (dd/mm/yyyy) and then manually deleted the rows


I would like to automate this process so that a message will appear "select date you wish to filter prior to this date"


once this is inputted , Col F must be filtered and the date filter must filter all the dates prior to the date inputted into the message box
for eg all dates prior to 01/10/2017 and then delete these rows




Your assistance in this regard is most appreciated
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hey howard,

Try the below code

Code:
Sub DeleteDates()
Dim dDate As Date
dDate = InputBox("Please enter the required date in proper format")
With ActiveSheet.UsedRange
    .AutoFilter Field:=6, Criteria1:="<" & dDate
    .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilter
End With
End Sub
 
Upvote 0
Thanks for your help.

I have tested your code and it is deleting some of the rows for the date specified

The code must filter the dates prior to the date selected and then delete those rows. For e.g. if I select 01/10/2017, then for eg 30/09/2017, 07/06/2017, 04/05/2016 etc to be filtered and then those rows deleted

In my example , I selected 01/10/2017 (format dd/mm/yyyy), but not all the dates prior to 01/10/2017 is being filtered and deleted


I have highlighted those dates in Yellow that have not being filtered and those rows deleted


I have also shown what the data must look like after filtering and the rows deleted on sheet "Manual Filter and Del"

Kindly test & amend your code


See link for sample data below



https://app.box.com/s/ufyh84xwp15ciloihnfndg52rhfvrrqt
 
Upvote 0
Hi howard,

Please add the bold text in the below line & try again

Rich (BB code):
.AutoFilter Field:=8, Criteria1:="<" & CLng(dDate)
 
Upvote 0
thanks for he help, much appreciated


what is the significance of & CLng(dDate) ?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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