Deleting Rows that Match/Contain Search Criteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
set rng = Columns("A:A").Find(What:="74RM",... )
if not rng is nothing then
rng.EntireRow.Delete
End if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top