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().
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().
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().
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().
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks