delete row contains specific word in an macro

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

Guest

Hi, Im trying to delete row that contains specific expression like:

In row 444 column b contents (ESSO PRODUITS) i want to delete that row but i
have more then one row to find and delete.
 
Try this on a spare copy:
Do a Data > Filter > Autofilter on col B
Select from the droplist: ESSO PRODUITS
Select all the filtered rows (select the "blue" row headers)
Right-click > Delete Row
Remove Autofilter
 
You can use data>filter>autofilter>filter on that column for that value
OR
a for/each macro to look, bottom up, for the value and then
..entirerow.delete
 
Ok manually, but in a macro how would do that?

Don Guillett said:
You can use data>filter>autofilter>filter on that column for that value
OR
a for/each macro to look, bottom up, for the value and then
..entirerow.delete
 
You could record a macro when you did the filtering and deleting to get your
code.

or looping (like Don's second suggestion):

Option Explicit
Sub testme()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long

With Worksheets("sheet1")
FirstRow = 2 'headers in 1???
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
If UCase(.Cells(iRow, "B").Value) = UCase("ESSO PRODUITS") Then
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub
 

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