Solved

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

Posted on 2013-01-24
5
227 Views
Last Modified: 2013-01-25
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
Comment
Question by:Jagwarman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:krishnakrkc
ID: 38813555
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
 

Author Comment

by:Jagwarman
ID: 38813597
Unfortunately that deletes the ones I want to keep :-(
0
 
LVL 18

Expert Comment

by:krishnakrkc
ID: 38813610
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
 

Author Comment

by:Jagwarman
ID: 38813703
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
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 500 total points
ID: 38813835
Hi

PFA.

Kris
DeleteRows.xlsb
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question