PC Review


Reply
Thread Tools Rate Thread

Delete Rows If Date Less Than Date Value

 
 
=?Utf-8?B?Sm9lIEsu?=
Guest
Posts: n/a
 
      4th Oct 2007

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,
 
Reply With Quote
 
 
 
 
Andrew
Guest
Posts: n/a
 
      4th Oct 2007
On 4 Oct, 22:04, Joe K. <Joe K...@discussions.microsoft.com> 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete all rows not current date SITCFanTN Microsoft Excel Programming 6 19th Nov 2009 01:38 PM
Delete rows based on date input bingshuo.li@gmail.com Microsoft Excel Programming 3 17th Nov 2008 11:01 PM
delete all rows where cell is not date format burl_h Microsoft Excel Programming 5 11th Feb 2008 01:44 AM
Delete Duplicate Rows, by Date field DTTODGG Microsoft Excel Programming 4 4th Feb 2008 11:38 PM
Excel VBA - Delete rows within a date range rott Microsoft Excel Programming 9 25th Feb 2004 02:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:12 PM.