Macro to delete rows prior to specific date

TheCman81

Well-known Member
Joined
Feb 28, 2012
Messages
535
Running Excel 2007.

Hi Guys,

I need a macro to delete all rows before the 16/Jan/2012? Date is in Column G and already sorted in desending order.

Hope someone can help!

Thanks

Colin
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi Colin & Welcome to the Board!

perhaps:

Code:
Sub Del_Rows()
With Activesheet
  .AutofilterMode = False
  .Range("A1:G1").AutoFilter
  .Range("A1:G1").Autofilter Field:=7,Criteria1:="<" & CLng(#16 Jan 2012#)
  .Autofilter.Range.Offset(1).EntireRow.Delete
  .AutofilterMode = False
End With
End Sub
 
Upvote 0
Code:
Sub DelDate()
Dim i
For i = Cells(Rows.Count, 7).End(xlUp).Row To 1 Step -1
On Error Resume Next
If Cells(i, 7).Value < "16.1.2012" Then
Rows(i).Delete
End If
Next
End Sub
 
Upvote 0
Thanks guys, both do work but Firefly's is much quicker, I have over 5000 lines and your Loop Matt takes quite long.

Thanks again for your help
 
Upvote 0

Forum statistics

Threads
1,214,587
Messages
6,120,406
Members
448,958
Latest member
Hat4Life

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