Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / June 2006

Tip: Looking for answers? Try searching our database.

delete rows with dates between

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dan - 30 Jun 2006 19:58 GMT
Hi,

I have a spreadsheet, column J has dates ranging from June05 - June 06.
I want to delete the entire row if the date falls between 06/01/2005
and 12/31/2005, and merge all the rows up.

I have tried a few things on here but havent gotten them to work for my
situation.

Thank you in advance for any help!
Barb Reinhardt - 30 Jun 2006 20:35 GMT
I've used something like this:

   Dim DeleteValue As String
   Dim rng As Range

   DeleteValue = "File(s)"
   ' This will delete the rows with "File(s)" in the Range("A2:A65536")
   With ActiveSheet
       .Range("A2:A65536").AutoFilter Field:=1, Criteria1:="=*File(s)*"
       '   Need to figure out how to enter DeleteValue above
       
       With ActiveSheet.AutoFilter.Range
           On Error Resume Next
           Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
                     .SpecialCells(xlCellTypeVisible)
           On Error GoTo 0
           If Not rng Is Nothing Then rng.EntireRow.Delete

       End With
       .AutoFilterMode = False
   End With

It could probably be more elegant, but it works.

> Hi,
>
[quoted text clipped - 6 lines]
>
> Thank you in advance for any help!
Yngve - 30 Jun 2006 21:34 GMT
dan skrev:
> Hi,
>
[quoted text clipped - 6 lines]
>
> Thank you in advance for any help!

Hi dan

This asume you have a header
Sub DeleteRows()

Dim i As Double, lastrow As Double, Mydate As Date, rngDate As Date
lastrow = Cells(Rows.Count, "J").End(xlUp).Row
Mydate = "06/01/2006"
With ActiveSheet
For i = lastrow To 2 Step -1
       rngDate = Range("J2").Offset((i - 2), 0).Value
       If rngDate < Mydate Then
       Range("J2").Offset((i - 2), 0).EntireRow.Delete
       
       End If
Next i
End With

End Sub

Regards Yngve
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.