PC Review


Reply
Thread Tools Rate Thread

Delete rows based on date criteria

 
 
Rookie_User
Guest
Posts: n/a
 
      12th Nov 2008
I have a worksheet named PVI_Info, it contains columns A - F. They all have
data in them. Column C has a date and I want a macro to look at the
worksheet and delete all rows that have a date ocurring before 03/22/08.
Then resort based on colum C oldest to newest.
I am usring 2007 Excel - any suggestions...

I have been looking but havent found anything to help yet.
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      12th Nov 2008
Hi,

Right click your sheet tab, view code and paste this and run it.

Sub copyit()
Dim Mydate As Date
Mydate = "22/3/2008"
Dim MyRange, MyRange1 As Range
lastrow = Cells(Rows.Count, "C").End(xlUp).Row
Set MyRange = Range("C1:C" & lastrow)
For Each c In MyRange
If c.Value < Mydate Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
lastrow = Cells(Rows.Count, "C").End(xlUp).Row
Range("A1:F" & lastrow).Sort Key1:=Range("C1"), Order1:=xlAscending
End Sub


Mike

"Rookie_User" wrote:

> I have a worksheet named PVI_Info, it contains columns A - F. They all have
> data in them. Column C has a date and I want a macro to look at the
> worksheet and delete all rows that have a date ocurring before 03/22/08.
> Then resort based on colum C oldest to newest.
> I am usring 2007 Excel - any suggestions...
>
> I have been looking but havent found anything to help yet.

 
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 rows based on multiple criteria puiuluipui Microsoft Excel Misc 6 3rd Jul 2009 01:58 PM
How can I delete rows programmatically based on certain criteria? =?Utf-8?B?bnRfYXJ0YWduaWFu?= Microsoft Excel New Users 2 8th Mar 2007 03:56 AM
filter and delete rows based on two criteria =?Utf-8?B?QXJub2xkIEtsYXBoZWNr?= Microsoft Excel Programming 0 1st Sep 2006 08:13 PM
Delete rows based on criteria =?Utf-8?B?Q2hyaXNfdF8yazU=?= Microsoft Excel Misc 2 11th Apr 2006 01:52 PM
Delete rows based on certain criteria =?Utf-8?B?Q29hbCBNaW5lcg==?= Microsoft Excel Misc 2 3rd Mar 2006 05:56 PM


Features
 

Advertising
 

Newsgroups
 


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