Results 1 to 5 of 5

Code to delete rows based on status code in Column I

Threaded View

  1. #1
    Registered User
    Join Date
    07-10-2008
    Location
    Norwich, England
    MS-Off Ver
    Office XP
    Posts
    15

    Code to delete rows based on status code in Column I

    I'm trying to write a VBA script which will delete all rows in my Excel spreadsheet where Column I (which contains a status code) does not contain the word "Completed".

    At the moment, I'm doing this the other way round: my script is able to search for entries in Column I which contain the status codes "Pending", "Awaiting Authorisation", "In Progress" etc and delete them. The idea is that when all those rows are deleted, I'll only be left with rows which have a status of "Completed". This works fine at the moment. However, the concern is that if a brand new status code is added to the data file, my script would be unable to pick it up and delete it.

    This is a small sample of the code I'm currently using (which deletes all the rows with statuses other than Completed):

     Dim rng As Range
        Dim search_string As String: search_string = "Pending"
        Dim lng_i As Long
        For lng_i = 1 To Application.CountIf(Columns(9), search_string) Step 1
            With ActiveSheet.Range("I:I"): .Find(search_string, LookIn:=xlValues).EntireRow.Delete: End With
        Next lng_i
    How can I re-write this so that it will delete all the rows where the status does not contain "Completed", regardless of whether new status codes are added in the future?
    Last edited by LemonTwist; 07-24-2009 at 11:29 AM. Reason: solved

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