Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Column G & H contain Dates. I would like to run a macro that deletes the
entire row where the date in column G "or" H is greater than today(). |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This should be close to what you want...
Sub DeleteRows() Dim wks As Worksheet Dim rngToSearch As Range Dim rngCurrent As Range Dim rngToDelete As Range Set wks = ActiveSheet Set rngToSearch = Range(wks.Range("G2"), wks.Range("G65536").End(xlUp)) For Each rngCurrent In rngToSearch If rngCurrent.Value Date Or rngCurrent.Offset(0, 1).Value Date Then If rngToDelete Is Nothing Then Set rngToDelete = rngCurrent Else Set rngToDelete = Union(rngToDelete, rngCurrent) End If End If Next rngCurrent If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete End Sub -- HTH... Jim Thomlinson "Matt Cromer" wrote: Column G & H contain Dates. I would like to run a macro that deletes the entire row where the date in column G "or" H is greater than today(). |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jim -
I am getting an compile error when I paste this in. The error is on these lines If rngCurrent.Value Date Or rngCurrent.Offset(0, 1).Value Date Then Do you have any idea what would cause this? Thanks for your help "Jim Thomlinson" wrote: This should be close to what you want... Sub DeleteRows() Dim wks As Worksheet Dim rngToSearch As Range Dim rngCurrent As Range Dim rngToDelete As Range Set wks = ActiveSheet Set rngToSearch = Range(wks.Range("G2"), wks.Range("G65536").End(xlUp)) For Each rngCurrent In rngToSearch If rngCurrent.Value Date Or rngCurrent.Offset(0, 1).Value Date Then If rngToDelete Is Nothing Then Set rngToDelete = rngCurrent Else Set rngToDelete = Union(rngToDelete, rngCurrent) End If End If Next rngCurrent If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete End Sub -- HTH... Jim Thomlinson "Matt Cromer" wrote: Column G & H contain Dates. I would like to run a macro that deletes the entire row where the date in column G "or" H is greater than today(). |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Delete an entire row | Excel Discussion (Misc queries) | |||
Delete entire row if | Excel Discussion (Misc queries) | |||
Delete Entire Row | Excel Programming | |||
macro to find date format in a cell and delete that entire row | Excel Programming | |||
Delete Entire Row. | Excel Programming |