LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Excel VBA - Delete rows within a date range

rott,

If your dates are in column A, then you can use the macro below. If the
dates are in another column, change all instances of [1] to correspond to
the actual column # - if the dates are in column H, for example, use [8].
You can either change the start and end dates in my code, or use global
variables to pass the dates in (in which case delete the Dim
statements......)

HTH,
Bernie
MS Excel MVP

Sub KeepDates()
Dim myRows As Long
Dim Start_Date As Date
Dim End_Date As Date
Start_Date = "1/2/4"
End_Date = "1/7/4"

Range("A1").EntireColumn.Insert
Range("A1").FormulaR1C1 = _
"=IF(ISNUMBER(RC[1]),IF(AND(RC[1]=DATEVALUE(""1/2/4"")," & _
"RC[1]<=DATEVALUE(""1/7/4"")), ""Keep"",""Trash""),""Keep"")"
myRows = ActiveSheet.UsedRange.Rows.Count
Range("A1").Copy Range("A1:A" & myRows)
With Range(Range("A1"), Range("A1").End(xlDown))
.Copy
.PasteSpecial Paste:=xlValues
End With
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
Columns("A:A").Find(What:="Trash", After:=Range("A1")).Select
Range(Selection, Selection.End(xlDown)).EntireRow.Delete
Range("A1").EntireColumn.Delete

End Sub

"rott " wrote in message
...
Hi I'm new to vba programming, here is my problem. I have 2 variables
one named start_date and the other end_date. What I am trying to do is
go through a worksheet and look at a cell in each row called startdate
and compare it to the dates that were entered into the variables above.
If the date in the cell in each row is not = to the start_date
variable and is not <= the end_date variable then I want to delete that
entire row. Basically if the date in the cell is not within the date
range of the two variables, then that row needs to be deleted.

It needs to go through the whole worksheet to eliminate all rows with
dates that don't fall within this range.

Can someone please help I am desperate.
Thanks


---
Message posted from http://www.ExcelForum.com/



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Count is not in a certain range, delete Rows CarolynRatcliffe Excel Discussion (Misc queries) 0 February 23rd 10 04:52 AM
Select a range of rows to delete Donna[_3_] Excel Worksheet Functions 2 January 26th 10 07:32 PM
Delete rows based upon a range of times farmboy Excel Discussion (Misc queries) 6 October 16th 09 05:02 PM
Macro to delete blank rows in a data range Youlan Excel Discussion (Misc queries) 5 September 17th 08 08:51 AM
delete rows in range - macro hindu cliparts Excel Worksheet Functions 0 November 16th 06 09:54 PM


All times are GMT +1. The time now is 02:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"