Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
If Count is not in a certain range, delete Rows | Excel Discussion (Misc queries) | |||
Select a range of rows to delete | Excel Worksheet Functions | |||
Delete rows based upon a range of times | Excel Discussion (Misc queries) | |||
Macro to delete blank rows in a data range | Excel Discussion (Misc queries) | |||
delete rows in range - macro | Excel Worksheet Functions |