+ Reply to Thread
Results 1 to 4 of 4

Deleting rows when a certain cell has a certain value

  1. #1
    Registered User
    Join Date
    08-08-2006
    Posts
    4

    Smile Deleting rows when a certain cell has a certain value

    Hi,

    Can someone help me with the next problem?
    I would like to create a Macro which deletes the line if the date value in a certain column is in the past.

    Thanks for your feedback,

    Leentje

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Hi paste this code in to the worksheet module, every time the sheet is activated it will search through the specified range and delete everything older than today!

    Hope it helps.

    Regards,
    Simon

    Option Explicit

    Private Sub Worksheet_Activate()
    Dim mycell
    Dim rng As Range
    Set rng = Range("A1:A100")
    For Each mycell In rng
    If mycell.Value < Date Then
    Application.ScreenUpdating = False
    mycell.EntireRow.Delete
    End If
    Next
    Application.ScreenUpdating = True
    End Sub

  3. #3
    Registered User
    Join Date
    08-08-2006
    Posts
    4
    When executing this macro, the odd lines are not checked.
    When executing the macro again various times the final result is ok.
    So I think I need to add some additional code to solve this...
    Can you help?

  4. #4
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    The code worked fine for me as long as the range it checks is formatted in Date format.
    Regards,
    Simon

+ 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