OzGrid

How to use VBA to delete rows based on multiple conditions

< Back to Search results

 Category: [Excel]  Demo Available 

How to use VBA to delete rows based on multiple conditions

 

Requirement:

 

The user requires a macro that would delete multiple conditions like:

 

1.) all cells that begins with DE and CHE and

2.) cells that are blank.

 

https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/1205392-vba-to-delete-rows-based-on-multiple-conditions

 

Solution:

 

Code:
Sub Deleter()

Range("B2").Select
Do Until IsEmpty(Range("A" & ActiveCell.Row))
    If ActiveCell = "" _
    Or IsEmpty(ActiveCell) _
    Or Len(ActiveCell) = 0 Then
        ActiveCell.EntireRow.Delete
    ElseIf Left(ActiveCell, 2) = "DE" Then
        ActiveCell.EntireRow.Delete
    ElseIf Left(ActiveCell, 3) = "CHE" Then
        ActiveCell.EntireRow.Delete
    Else
        ActiveCell.Offset(1, 0).Select
    End If
Loop

End Sub

 

Obtained from the OzGrid Help Forum.

Solution provided by chirayuw.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to loop each row if there is data after green colour cell then delete
How to use Excel VBA to delete rows in a column based on a range of cells in another column
How to count and delete duplicate entries over multiple columns
How to delete rows based on cell content

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.

 

 


Gallery



stars (0 Reviews)