Deleting Dates Outside of Range

jethomps8

New Member
Joined
Oct 12, 2010
Messages
1
So I am new to using macros and am looking for some help.

I am hoping to do two things.

1) Create a macro that will quickly and automatically delete data that is outside of the date range I am interested in. (I think a date search, then a group delete would be quickest, but am unsure of how to do this)

2) Instead of opening the macro and editing the date range via code, I would prefer a simple userform that uses txt boxes to insert the dates into the code.

Below is the code I have gotten so far. I am currently using a loop function to delete rows outside my date range, but its relatively slow.

Code:

Sub FormatData()
'Arrange Date by Req ID
Rows("1:1").Select
Selection.AutoFilter
Range("A1:X1187").Sort Key1:=Range("X1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'Adjust width of Column A to show all of date
Columns("A:A").EntireColumn.AutoFit
End Sub
Range("A:A").NumberFormat = "m/d/yyyy"
Rows(2).Select
ActiveWindow.FreezePanes = True
Rows(1).AutoFilter

'Create a variable that = the last used row in column A
LR = Cells(Rows.Count, "A").End(xlUp).Row

'Create a looping variable # to go backwards from the last used Row# to 1
For i = LR To 2 Step -1
If Cells(i, "A").Value < #9/27/2010 7:00:00 AM# Or Cells(i, "A").Value > #9/28/2010 7:00:00 AM# Then
Rows(i).EntireRow.Delete shift:=xlUp
End If
Next i
End Sub

</PRE>
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,215,471
Messages
6,125,000
Members
449,202
Latest member
Pertotal

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