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:
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:
.AutoFilter 1, “<>Product B”
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.