I'm having a little trouble getting this sorted. In column A I have a list of letters: A, B, D, M and N. I need to loop through each cell, and delete all rows that contain B, M, N, as well as blanks. Here's my code:
My problem here is this isn't deleting the rows that contain the letter N. If I run the macro, it deletes rows that contain B, M, and blanks, and then if I run it a second time, it WILL delete the rows containing the letter N. Any ideas on what's going on here? I've attached a workbook with the code contained in a module. Thanks![]()
Sub Main() Dim lastrow As Double lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row For Each cell In ThisWorkbook.ActiveSheet.Range("A1:A" & lastrow) If cell.Text = "B" Or cell.Text = "M" Or cell.Text = "N" Or cell.Text = "" Then cell.EntireRow.Delete End If Next cell End Sub
Bookmarks