+ Reply to Thread
Results 1 to 3 of 3

VBA delete row with cell contains specific values

Hybrid View

  1. #1
    Registered User
    Join Date
    05-25-2020
    Location
    Denmark
    MS-Off Ver
    Professional Plus 2016
    Posts
    58

    VBA delete row with cell contains specific values

    This is driving me nuts as I have made a similar script few years ago. However, it's not to be found.

    I want to add more values like 1009230, 1009231, etc. . I know it can be done with array but I am missing something.

    Current script works with single value.

    Best Thoms



    Capture.PNG


    Formula: copy to clipboard


    Sub BD_DELETE()

    Dim rng As Range
    Set rng = ActiveSheet.UsedRange

    For i = rng.Cells.Count To 1 Step -1
    If rng.Item(i).Value = "1009229" Then
    rng.Item(i).EntireRow.Delete
    End If
    Next i
    End Sub




  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA delete row with cell contains specific values

    Try this code. The key is to convert the text in the array to a number.

    Sub BD_DELETE()
    Dim arr
    Dim rng As Range
    Dim i, x As Long
        
    Set rng = ActiveSheet.UsedRange
    arr = Array("1009233", "1009236")
        
    For x = 0 To UBound(arr)
        
        For i = rng.Cells.Count To 1 Step -1
    
            If CLng(arr(x)) = rng.Item(i).Value Then
     
                rng.Item(i).EntireRow.Delete
    
            End If
    
        Next i
    
    Next x
    
    End Sub

  3. #3
    Registered User
    Join Date
    05-25-2020
    Location
    Denmark
    MS-Off Ver
    Professional Plus 2016
    Posts
    58

    Re: VBA delete row with cell contains specific values

    This is perfect! Thanks for the tip and code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Delete rows with specific values
    By louvaek in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-13-2019, 09:34 PM
  2. [SOLVED] Delete rows which contain specific values
    By Blake 7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-22-2015, 08:58 AM
  3. [SOLVED] How to delete a row with specific values in a that fall between certain numbers
    By John Swift in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2014, 08:27 AM
  4. [SOLVED] Delete Row if Cell Contains Specific Values (Multiple Criteria)
    By efarkouh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-01-2014, 11:38 AM
  5. delete specific rows based on values in that row
    By bstinson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-05-2013, 03:46 PM
  6. Excel 2007 : How to delete specific values from rows?
    By leonlwf in forum Excel General
    Replies: 1
    Last Post: 06-01-2012, 12:03 AM
  7. Delete rows with specific column values
    By koklok in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-16-2008, 01:51 PM

Tags for this Thread

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