Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Delete Rows If Date Less Than Date Value


I have a worksheet with dates that are inserted ascending order in column A.
I would like to delete date rows in column A, if they are less than a define
date value ('09-26-2007'), next shift all of the rows up by one below the
deleted row.

Please help me with a simple script to complete this task.

Thanks,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Delete Rows If Date Less Than Date Value

On 4 Oct, 22:04, Joe K. <Joe wrote:
I have a worksheet with dates that are inserted ascending order in column A.
I would like to delete date rows in column A, if they are less than a define
date value ('09-26-2007'), next shift all of the rows up by one below the
deleted row.

Please help me with a simple script to complete this task.

Thanks,


Hi

Assuming that the dates are indeed already sorted, and that the dates
start in A1, this should do the job:


Sub RemoveDates()
Dim datFirstRequiredDate As Date
Dim rng As Range
Dim i As Integer

'Find out the first date to keep
datFirstRequiredDate = _
InputBox("Enter the first date that you want to keep")

'Start with A1
Set rng = Range("A1")
'Count the number of rows to remove

Do Until rng.Offset(i).Value = datFirstRequiredDate
i = i + 1
Loop
'Remove from row 1 to the last non-required row
'NOTE: if you want to keep row 1 (eg if it contains headings
' you will need to alter the line to ... .Rows("2:" & i).....

ActiveSheet.Rows("1:" & i).EntireRow.Delete

End Sub

Reply
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
Macro to delete rows based on date PMBO Excel Discussion (Misc queries) 4 February 18th 09 01:50 PM
Delete rows with date more than 48 hours with a condition.. Kashyap Excel Worksheet Functions 4 February 5th 09 03:51 AM
delete rows in excel by service date [email protected] Excel Programming 4 May 29th 07 07:13 PM
How do you format an auto update to delete rows with expired date Rneedshelp Excel Worksheet Functions 0 May 29th 07 04:30 PM
Excel VBA - Delete rows within a date range rott Excel Programming 8 February 24th 04 07:38 PM


All times are GMT +1. The time now is 07:46 AM.

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

About Us

"It's about Microsoft Excel"