This post will guide you how to use the Find & Replace feature to delete or remove all rows based on certain cell value in Microsoft Excel. Or how to delete all rows that contain certain value with VBA code in excel, such as, removing all rows if cell contains 0 or any other value.
Assuming that you have a worksheet and you want to delete rows based on cell vlaue if the value is equal to 0. In another word, if the cell value contain 0, then delete that row contain value 0. The first thing you need to do is that how to find rows that contain certain value in your worksheet. And how to solve this problem? You can use the Find & Replace command or VBA code to achieve the result.
Delete rows based on cell value with Find & Replace feature
To delete rows based on a certain cell value with Find & Replace feature, you can refer to the following steps:
1# Select the range of cells that you want to delete rows based on certain cell value.
2# on the HOME tab, click Find & Replace command under Editing group. Or just press Ctrl +F shortcut to open the Find and Replace box.
3# the Find and Replace dialog box will appear on the screen.
4# type the certain value in the Find what: text box, and then click Find All button
5# you will see that the searched result will appear in the Find and Replace window.
6# select all found values in the Find and Replace window and you will see that all cells contain certain value will be highlighted in your selected range.
7# right-click on the selected cells, and select Delete…menu from the drop-down menu list. Then choose Entire row radio button in the Delete dialog box. Click OK button.
Or you can go to HOME tab, click Delete command. Then click Delete Sheet Rows.
So far, all rows contain the certain value are deleted in your selected range. And if you want to remove the columns base on the certain value, just select Entire column radio button in the step 7.
Delete Rows Based on cell value with Excel VBA Macro (VBA code)
If you want to delete rows that contain the certain value in your worksheet with excel VBA Marco, you can refer to the following steps:
1# click on “Visual Basic” command under DEVELOPER Tab.
2# then the “Visual Basic Editor” window will appear.
3# click “Insert” ->”Module” to create a new module
4# paste the below VBA code into the code window. Then clicking “Save” button.
Sub RemoveRowsBasedValue() Dim Dr As Range Set Ip = Application.Selection Set Ip = Application.InputBox("Select one range that you want to remove rows:", "RemoveRowsBasedValue", Ip.Address, Type:=8) Ds = Application.InputBox("Please type a text string:", "RemoveRowsBasedValue", Type:=2) For Each R In Ip If R.Value = Ds Then If Dr Is Nothing Then Set Dr = R Else Set Dr = Application.Union(Dr, R) End If End If Next Dr.EntireRow.Delete End Sub
5# back to the current worksheet, then run the above excel macro. Click Run button.
6# select a range that you want to delete rows, click OK button. Then type a text string contained in the range of rows to delete.