+ Reply to Thread
Results 1 to 5 of 5

Thread: Macro to delete rows not containing a specified value

  1. #1
    Registered User
    Join Date
    02-01-2012
    Location
    texas
    MS-Off Ver
    Excel 2011
    Posts
    10

    Macro to delete rows not containing a specified value

    Hi,

    I am needing a macro that will delete entire rows (up to 3000 rows) not containing a specified value(i.e. "100") in Column C. Row 1 contains titles for the columns.I have tried this on my own, but I am having trouble. I have seen a few that when the macro is started it propts you to input the value that you want to not delete. Any help would be appreciated. Solved
    Last edited by jhmayor03; 02-02-2012 at 10:29 AM. Reason: Solved

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    359

    Re: Macro to delete rows not containing a specified value

    You could use this - It will ask for a number using an inputbox and any row NOT containing the number will be deleted
    Sub srchDel()
    Dim questDel As Long
    questDel = Application.InputBox(Prompt:= _
            "Please Select a Number as Criteria Not to Delete", _
            Title:="InputBox Method", Type:=1) 'Type 1 is a number, 2 is a string
    lrow = Cells(Rows.Count, "C").End(xlUp).Row
    Set xRng = Columns("C:C")
    Set yRng = Range("C2:C" & lrow)
      
    On Error Resume Next
    With xRng
       .AutoFilter Field:=1, Criteria1:="<>" & questDel, Operator:=xlAnd
          yRng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
       .AutoFilter
    End With
    On Error Goto 0
    End Sub
    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”

  3. #3
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    359

    Re: Macro to delete rows not containing a specified value

    PS: You could set the Type to the various attributes for the Inputbox depending on what you are searching for
    0 A formula
    1 A number
    2 Text (a string)
    4 A logical value (True or False)
    8 A cell reference, as a Range object
    16 An error value, such as #N/A
    64 An array of values
    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”

  4. #4
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    359

    Re: Macro to delete rows not containing a specified value

    -delete - double post

  5. #5
    Registered User
    Join Date
    02-01-2012
    Location
    texas
    MS-Off Ver
    Excel 2011
    Posts
    10

    Re: Macro to delete rows not containing a specified value

    This Macro works perfectly!!! Thanks so much for the help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0