![]() |
Delete Entire Row - Date
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(). |
Delete Entire Row - Date
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(). |
Delete Entire Row - Date
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(). |
All times are GMT +1. The time now is 12:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com