+ Reply to Thread
Results 1 to 2 of 2

VBA for deleting rows not based on criteria

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-23-2007
    Location
    Suffolk, UK
    Posts
    298

    VBA for deleting rows not based on criteria

    Hello,

    I have data that is produced every week and added to a data sheet, this holds all the data for the year, I need to remove data rows that do not matched 4 customers (column G) and keep the rest of the row data specific to those customers, at present it is done manually and not very efficient.

    Is there a way of removing this using VBA?

    The 4 customers are "BURHILL";"CSA";"COSC" & "DEBE".

    I have attached a worksheet that illustrates what I mean the highlighted rows are the ones to be deleted and rows that are required need to be moved up so there a no gaps?

    thanks reg
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: VBA for deleting rows not based on criteria

    Try the following

    Sub Del_Unwanted()
    Dim row_index As Long
    
    Application.ScreenUpdating = False
    ' Go through each row that has data in G (in reverse order so that the deletion of rows doesn't effect row numbering of rows we haven't worked on yet)
    For row_index = Cells(Rows.Count, "G").End(xlUp).row To 1 Step -1
        Select Case Cells(row_index, "G")
            Case "BURHILL", "CSA", "COSC", "DEBE"
            Case Else ' If it's not one of the wanted ones, delete the entire row
                Rows(row_index).EntireRow.Delete
        End Select
    Next
    Application.ScreenUpdating = True
    End Sub
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

+ 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