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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,213,543
Messages
6,114,240
Members
448,555
Latest member
RobertJones1986

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