View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Automatic Conditional Row Deletion?

I'm now going to sit in a darkened room and contemplate the benefits of age,
now where shall I begin:-

No.1......errrrm hang on I'll think of one.

Mike

"Barb Reinhardt" wrote:

You beat me to it. I wasn't sure if I wanted to respond because I'm a
Yellow Jacket in Terps country.

:)

Barb Reinhardt



"Mike H" wrote:

Hi,

It's with some personal pain that I'm to be deleted because I'm over 40 (in
fact twice that) thatI offer you this solution to consider. Right click the
appropriate sheet tab, view code and paste this in on the right. Every time
you select the sheet those poor souls older than 40 are deleted.

Private Sub Worksheet_Activate()
Dim MyRange, MyRange1 As Range
lastrow = Cells(Rows.Count, "H").End(xlUp).Row
Set MyRange = Range("H1:H" & lastrow)
For Each c In MyRange
If IsDate(c.Value) And Int((Date - c.Value) / 365.25) 40 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.Select
End If
Selection.Delete
Range("A1").select
End Sub

Mike

"Go Terps" wrote:

I have a spreadsheet with birthdates listed in column H. Is it possible to
have certain rows automatically deleted when they hit 40 years old (or older)?