+ Reply to Thread
Results 1 to 3 of 3

Delete Entire Row - Date

  1. #1
    Matt Cromer
    Guest

    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().

  2. #2
    Jim Thomlinson
    Guest

    RE: 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().


  3. #3
    Matt Cromer
    Guest

    RE: 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().


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1