title: How can I delete rows that don't meet conditions of user input?
body: <p>I want to record a macro that will delete any row in a data table that DOES NOT match a cell value in Column G that a user defines and shifts the remaining rows up. For example, if I want to delete any rows that don't have "Dec 2018" in Column G.</p>
  
  <p>My understanding is that this code from Excel Campus below could generate a pop up box for a user to define what they're looking for, but I am unclear on how to change the conditions so that it deletes any row that doesn't match the condition rather than matching the condition:</p>
  
  <pre><code>Sub RemoveOldReleases()
  'Display Yes/No message prompt before deleting rows
  'Source: https://www.excelcampus.com/vba/delete-rows-cell-values/
  
  Dim lo As ListObject
  Dim lRows As Long
  Dim vbAnswer As VbMsgBoxResult
  Dim sCriteria As Variant
  
    'Set reference to the sheet and Table.
    Set lo = RAW.ListObjects(1)
    lo.Parent.Activate 'Activate sheet that Table is on.
  
    'Clear any existing filters
    lo.AutoFilter.ShowAllData
  
    'Ask user for input
    sCriteria = Application.InputBox(Prompt:="Please enter the release month your trying to keep in the format Sep 2018" _
                                      &amp; vbNewLine &amp; "Leave the box empty to filter for blanks.", _
                                      Title:="Filter Criteria", _
                                      Type:=2)
  
    'Exit if user presses Cancel button
    If sCriteria = False Then Exit Sub
  
    '1. Apply Filter
    lo.Range.AutoFilter Field:=7, Criteria1:=sCriteria
  
    'Count Rows &amp; display message
    On Error Resume Next
      lRows = WorksheetFunction.Subtotal(103, lo.ListColumns(1).DataBodyRange.SpecialCells(xlCellTypeVisible))
    On Error GoTo 0
  
    vbAnswer = MsgBox(lRows &amp; " Rows will be deleted.  Do you want to continue?", vbYesNo, "Delete Rows Macro")
  
    If vbAnswer = vbYes Then
  
      'Delete Rows
      Application.DisplayAlerts = False
        lo.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete
      Application.DisplayAlerts = True
  
      'Clear Filter
      lo.AutoFilter.ShowAllData
  
    End If
  
  End Sub
  </code></pre>
  
  <p>Here is a screenshot of my data table: <a href="https://i.stack.imgur.com/KhXmK.png" rel="nofollow noreferrer">https://i.stack.imgur.com/KhXmK.png</a></p>
  
  <p>My workbook name: MasterSKUImport.xlsm</p>
  
  <p>My worksheet name: RAW</p>
  
  <p>Cell Range: A1:J100000</p>
  
  <p>Column with value: G</p>
  
  <p>Example of a value to search for: "Sep 2018"</p>
  
  <p>Bonus points if I can generate the default value in the pop up box to always be the previous month in the format Mmm YYYY (Sep 2018).</p>
  
  <p>UPDATE:</p>
  
  <p>I've tried this code as suggested by @SJR and it works!:</p>
  
  <pre><code>Sub RemoveOldReleases()
  
  Dim ws As Worksheet
  
  Set ws = ThisWorkbook.Worksheets("RAW")
  
    'Ask user for input
    sCriteria = Application.InputBox(Prompt:="Please enter the Release Month you're trying to keep in the format Mmm YYYY (ex. Sep 2018)", _
                                  Title:="Release Month", _
                                  Default:=Format(DateAdd("m", -1, Date), "mmm yyyy"), _
                                      Type:=2)
  
    'Exit if user presses Cancel button
    If sCriteria = False Then Exit Sub
  
    '1. Apply Filter
    ws.Range("$A$1:$J$100000").AutoFilter Field:=7, Criteria1:="&lt;&gt;*" &amp; sCriteria &amp; "*", Operator:=xlFilterValues
  
      'Delete Rows
      Application.DisplayAlerts = False
        ws.Range("$A$2:$J$100000").SpecialCells(xlCellTypeVisible).Delete
      Application.DisplayAlerts = True
  
      'Clear Filter
      ws.Range("$A$1:$J$100000").AutoFilter
  
  End Sub
  </code></pre>