Solved

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

Posted on 2013-01-24
5
219 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
  • 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now