Link to home
Start Free TrialLog in
Avatar of Jagwarman
Jagwarman

asked on

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
Avatar of krishnakrkc
krishnakrkc
Flag of India image

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
Avatar of Jagwarman
Jagwarman

ASKER

Unfortunately that deletes the ones I want to keep :-(
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
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
ASKER CERTIFIED SOLUTION
Avatar of krishnakrkc
krishnakrkc
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial