How to delete certain rows in excel

Exhelpp

New Member
Joined
Oct 20, 2016
Messages
24
Hi.

I was looking for some assistance please, I have spent the best part of today trying to find a way to do this but really struggling

Whilst browsing online I found a few examples but when I tried using these none of them have worked for me

I have a workbook with several worksheets, on each worksheet I need to delete all rows that meet the following criteria

1, All cells in columns B that are blank, and
2, All cells in column B that contain text "Blue" or "Black"

As far as deleting all rows that are blank I have this working using the following coding

Code:
If wst.Name Like "Open" = False Then
    On Error Resume Next
    wst.Columns("B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End If
    
    Next wst

But i am not sure why the following does not work? it does remove all the blank rows but doesnt delete the rows where column b contains blue or black

Code:
If wst.Name Like "Open" = False Then
    On Error Resume Next
    wst.Columns("B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End If
    
With ActiveSheet
    .AutoFilterMode = False
    With Range("b1", Range("b" & Rows.Count).End(xlUp))
        .AutoFilter 1, "*Blue*" or "*Black*"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.Delete
    End With
    .AutoFilterMode = False
End With

Next wst

Any help is appreciated, thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
How about
VBA Code:
   If wst.Name Like "Open" = False Then
       On Error Resume Next
       wst.Columns("B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
       On Error GoTo 0
       
      With wst
          .AutoFilterMode = False
          .Range("b1", .Range("b" & Rows.Count).End(xlUp)).AutoFilter 1, "*Blue*", xlOr, "*Black*"
          .AutoFilter.Range.Offset(1).EntireRow.Delete
          .AutoFilterMode = False
      End With
   End If
Next wst
 
Upvote 0
Cross posted Unable to delete rows using VBA

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,213,483
Messages
6,113,919
Members
448,533
Latest member
thietbibeboiwasaco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top