+ Reply to Thread
Results 1 to 2 of 2

Delete if in list

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Delete if in list

    Hello!

    I want to define a list, and delete row if the the column contains a value in the list:

    Something like this

    Sub deleteIFinlist
    
    Dim List
    99998
    99984
    99994
    
    For rwNum = lastRow To 1 Step -1
       If Cells(rwNum, "h") = List or then
       Cells(rwNum, "h").EntireRow.Delete
    End If 
    Next
    
    
    End sub

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Delete if in list

    Here's something that may be close to what you want:
    Sub deleteIFinlist()
    
        Dim List() As Variant    ' the list of values to be deleted
        List = Array(99998, 99984, 99994)
    
        ' find the last row of the used range
        Dim lastRow As Long
        Dim theRange As Range
        Set theRange = Sheet1.UsedRange
        lastRow = theRange.Rows(theRange.Rows.Count).Row
    
    
    
        ' loop through all of the rows backwards
        Dim rwNum As Long
        For rwNum = lastRow To 1 Step -1
    
            ' search for the value in column H of this row
            Dim i As Long
            For i = LBound(List) To UBound(List)
                If (Sheet1.Cells(rwNum, 8).Value = List(i)) Then
    
                    ' delete the row
                    Sheet1.Rows(rwNum).EntireRow.Delete
                    Exit For
                End If
            Next i
        Next rwNum
    
    End Sub
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

+ 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