PC Review


Reply
Thread Tools Rate Thread

Deleting Rows that Match/Contain Search Criteria

 
 
=?Utf-8?B?UG9zc2UgSm9obg==?=
Guest
Posts: n/a
 
      23rd Feb 2007
I import data for an external source into Excel. I sort and format the data
programatically.

This data contains some information that I need to delete. Searching that
range by using the following:

Columns("A:A").Find(What:="74RM",... ).Activate

How do I delete the entire row when the search criteria is found? I'm also
having difficulty understanding how to trap the error that occurs when the
search critieria is not found.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      23rd Feb 2007
This will go thru all the cells in column A, find the cells containing the
string "74RM" and delete the entire row. If non are found, no rows are
deleted:


Sub posse()
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = lastrow To 1 Step -1
If InStr(Cells(i, "A").Value, "74RM") > 0 Then
Cells(i, "A").EntireRow.Delete
End If
Next
End Sub



--
Gary's Student
gsnu200707


"Posse John" wrote:

> I import data for an external source into Excel. I sort and format the data
> programatically.
>
> This data contains some information that I need to delete. Searching that
> range by using the following:
>
> Columns("A:A").Find(What:="74RM",... ).Activate
>
> How do I delete the entire row when the search criteria is found? I'm also
> having difficulty understanding how to trap the error that occurs when the
> search critieria is not found.
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      23rd Feb 2007


set rng = Columns("A:A").Find(What:="74RM",... )
if not rng is nothing then
rng.EntireRow.Delete
End if

--
Regards,
Tom Ogilvy


"Posse John" wrote:

> I import data for an external source into Excel. I sort and format the data
> programatically.
>
> This data contains some information that I need to delete. Searching that
> range by using the following:
>
> Columns("A:A").Find(What:="74RM",... ).Activate
>
> How do I delete the entire row when the search criteria is found? I'm also
> having difficulty understanding how to trap the error that occurs when the
> search critieria is not found.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to count rows that match two criteria? Broida (spamless) Microsoft Excel Discussion 4 2nd Jan 2005 09:59 PM
How to count rows that match two criteria? Broida (spamless) Microsoft Excel Discussion 1 2nd Jan 2005 02:46 AM
Deleting a row when cell's value doesn't match a criteria ? Grek Microsoft Excel Programming 2 30th Jun 2004 11:05 PM
Get rows which match selection criteria Fred Smith Microsoft Excel Programming 1 21st Feb 2004 03:52 AM
deleting cetain rows that match a criteria electric_d Microsoft Excel Misc 6 12th Feb 2004 06:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:28 PM.