Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

VBA to delete rows that do not contain the words Proven or Under Investigation

Can someone assist in providing me with some code to delete rows that do not contain the words Proven or Under Investigation [which could be in either Lower or Uppercase] The Column these will be found in is 'I' so I only want to keep the rows that contain either of those words.

Thank you
0
Jagwarman
Asked:
Jagwarman
  • 3
  • 2
1 Solution
 
krishnakrkcCommented:
Hi

Try

Option Explicit

Sub kTest()
    
    Dim r   As Range
    
    Set r = Range("I2:I1000")        'adjust to suit
    
    With r
        .AutoFilter 1, "<>Proven", xlAnd, "<>Under investigation"
        On Error Resume Next
        .Offset(1).Resize(.Rows.Count - 1, 1).SpecialCells(12).EntireRow.Delete
        .AutoFilter
    End With
    
    Application.ScreenUpdating = 1
    
End Sub

Open in new window


Kris
0
 
JagwarmanAuthor Commented:
Unfortunately that deletes the ones I want to keep :-(
0
 
krishnakrkcCommented:
Hi

Are you sure ? Your title says you want to keep Proven and Under inverstigation rows, right ? If not,

replace
.AutoFilter 1, "<>Proven", xlAnd, "<>Under investigation"

Open in new window


with

.AutoFilter 1, "=Proven", xlOr, "=Under investigation"

Open in new window


Kris
0
 
JagwarmanAuthor Commented:
yes I want to keep Proven and under investigation but when I run it, it deletes those and keeps everything else. I am using Excel 2010
0
 
krishnakrkcCommented:
Hi

PFA.

Kris
DeleteRows.xlsb
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now