While working with data in Excel, the deletion of an Excel row is quite a common phenomenon. However, there are a good number of methods that we can use to delete an Excel row If a cell contains specific text within it. Additionally, different approaches seem to work in different situations for specific values in cells. In this article, I will show 3 effective techniques to delete a row if a cell contains specific values in Excel with examples and proper illustrations.
Download Practice Workbook
You are recommended to download the Excel file and practice along with it.
3 Easy Methods to Delete Row If Cell Contains Specific Values in Excel
Here, we will be using a sample dataset to demonstrate all the methods in this tutorial. However, it contains the Name and Age of some persons.
So, without having any further discussion let’s get into all the methods one by one.
1. Use Find and Replace to Delete Row If Cell Contains Specific Text in Excel
Let’s say, we want to delete all the records that are started with “Mr.” in the Name column. Hence, follow the steps below.
🔗 Steps:
- First, press CTRL + F to open with Find and Replace window.
- Then, type “Mr.” within the Find what bar.
- After that, click on the Find All option.
- Now, select one of the found results and then press CTRL + A button ▶ to select all the found results.
- As you’ve successfully selected all the found results, now hit the Close option.
- Now, press CTRL + – button to open up the Delete dialog box.
- After that, select the Shift cells up option and hit OK.
- Lastly, the output will appear as below.
Read More: How to Delete Rows in Excel: 7 Methods
2. Utilize AutoFilter to Remove an Excel Row If Cell Contains Certain Value
In this method, we will delete all the Excel records starting with “Ms. Liesel” in the Name column using the AutoFilter feature in Excel. Hence, follow the steps below.
🔗 Steps:
- Initially, select the entire data table.
- Then, go to Data ▶ Sort & Filter ▶ Filter.
- Next, click on the drop-down icon at the down-right corner in the Name column.
- Afterwards, go to Text Filters ▶ Begins With option.
- At this point, a dialog box name Custom AutoFilter will pop up on the screen.
- Now, type Ms. Liesel within the begins with the bar and hit OK.
- After that, press CTRL + – button and a dialog box like the below image will appear on the screen.
- Lastly, just hit the OK button.
- Now, the output will look like the below image.
Read More: How to Delete Entire Row Based on Cell Value Using VBA in Excel
Similar Readings
- How to Delete Multiple Rows in Excel Using Formula (5 Methods)
- Delete Multiple Rows in Excel at Once (5 Methods)
- How to Delete Hidden Rows in Excel VBA (A Detailed Analysis)
- Delete Rows in Excel without Affecting Formulas (2 Quick Ways)
- How to Delete Row Using Macro If Cell Contains 0 in Excel (4 Methods)
3. Delete Row If Cell Contains Specific Values in Excel Using VBA Code
In this section, we will delete a row if any cell within it contains any text or number using VBA code.
3.1 Delete Row If Cell Contains Specific Text
In this method, we will try to delete a row having age 17 in the Age column. Hence, follow the steps below.
🔗 Steps:
- Firstly, press ALT +F11 to open the VBA window.
- Secondly, go to Insert ▶ Module to open a new module.
- Thirdly, copy the following code:
Sub DeleteRowsContainingtext()
Dim A As Worksheet
Dim B As Integer
Dim Step As Long
Set A = Worksheets("VBA")
For B = A.Range("B5:C14").Rows.Count To 1 Step -1
If Application.WorksheetFunction.IsText(Cells(B + 2, 2)) = True Then
A.Cells(B + 2, 2).EntireRow.Delete
End If
Next
End Sub
- Fourthly, paste it on the VBA editor and Save it by pressing CTRL + S.
- Finally, hit the F5 key to run the code and you will get your desired output.
Read More: How to Delete All Rows Not Containing Certain Text in Excel
3.2 Delete Row If Cell Contains Number
In this method, we will discuss how you can actually delete any row if any cell in column Age contains any number within it. Hence, follow the steps below.
🔗 Steps:
- Press ALT +F11 to open the VBA window.
- Now, go to Insert ▶ Module to open a new module.
- Copy the following code:
Sub DeleteRowsContainingNumbers()
Dim A As Long
Dim B As Long
A = 1000
For B = A To 1 Step -1
If Cells(B, 3).Value = "17" Then
Rows(B).Delete
End If
Next
End Sub
- Paste it on the VBA editor and Save it by pressing CTRL + S.
- Finally, hit the F5 key to run the code and you will get your desired output.
Read More: Excel VBA to Delete Rows with Specific Data (9 Examples)
Things to Remember
- Firstly, press CTRL + F to open the Find and Replace dialog box.
- Secondly, CTRL + – is the hotkey for deletion.
- Lastly, you can press ALT + F11 to open the VBA window.
Conclusion
To wrap up, we have illustrated 3 different methods, to delete a row if a cell contains a specific value in Excel. You are recommended to download the practice workbook attached along with this article and practice all the methods with that. And don’t hesitate to ask any questions in the comment section below. We will try to respond to all the relevant queries asap.
For more information like this, visit Exceldemy.com.