Delete rows using a macro

S

Sasikiran

Hello,

I need help with a macro that will delete certain rows in a spreadsheet.
The rows that need to be deleted are never in the same place, or the same
number of rows. The thing that the rows I want to delete all have in common
a specific word say "YES" in the same column. But they are never in the same
place everytime.

Please suggest me on this.
 
G

Gary''s Student

Here is a typical example. The macro deletes any rows with "YES" in column B:

Sub YESMan()
n = Cells(Rows.Count, "B").End(xlUp).Row
For i = n To 1 Step -1
If Cells(i, "B").Value = "YES" Then
Cells(i, "B").EntireRow.Delete
End If
Next
End Sub
 
S

Sasikiran

Thanks a ton :)

Gary''s Student said:
Here is a typical example. The macro deletes any rows with "YES" in column B:

Sub YESMan()
n = Cells(Rows.Count, "B").End(xlUp).Row
For i = n To 1 Step -1
If Cells(i, "B").Value = "YES" Then
Cells(i, "B").EntireRow.Delete
End If
Next
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

Top