Delete Rows Based On Conditions

If you are seriously after a VBA code to help you out in order to delete all the rows based on specific text found in a particular column, then this article is for you. In this article, we will learn how to delete a row if the specific text is found in a column.


Question): I have a file where I just need those rows which have “Product B” in column B. I want to delete everything else. Can someone please help me to write a macro? Following is the snapshot of data we have: img1


We need to follow the below steps:

  • Click on Developer tab
  • From Code group, select Visual Basic



Enter the following code in the standard module:

Sub DeleteRow()

With Sheet1.Cells(1).CurrentRegion.Columns(2)

.AutoFilter 1, "<>Product B"


End With

End Sub


Code explanation:

Step 1) The above code will select current region from column 2 i.e. Product column


Step 2) Apply Filter



Step 3) The visible cells will be deleted with entire row. Delete code. Rest of the data i.e. where Product B exists in column B will be our output.




In this way, using VBA code, we can delete rows meeting specific conditions.

image 19



Download - Delete rows based on conditions - xlsm

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.