How to remove rows based on cell value in Excel?
To quickly delete or remove multiple rows based on cell value in Excel, you may need to select those entire rows containing specific cell value first, and then go to remove them. It seems that there isn’t a quick way to delete rows based on cell value but using VBA code. Here are some quick tricks to help you.
- Remove rows based on one cell value with Find and Replace function
- Remove rows based on one cell value with VBA code
- Remove rows based on one or two cell values
- Remove rows based on multiple cell values
In Excel, you can apply the powerful Find and Replace feature to remove rows based on a certain cell value easily. Please do as follows:
1. Select the range where you will remove rows based on certain cell value, and open the Find and Replace dialog box with pressing the Ctrl + F keys simultaneously.
2. In the Find and Replace dialog box, please type the certain cell value (in our case, we enter the Soe) into the Find what box, and click the Find All button. See the first screenshot below:
3. Select all searching results at the bottom of Find and Replace dialog box, and close this dialog box. (Note: You can select one of searching result, and then Ctrl + A keys to select all found results. See the second screenshot above.)
And then you can see all the cells containing the certain value are selected.
4. Go ahead to right click selected cells and select the Delete from the right-clicking menu. And then check the Entire row option in the popping up Delete dialog box, and click the OK button. Now you will see all the cells containing the certain value are removed. See screenshots below:
And then entire rows have been deleted based on the certain value already.
With the following VBA code, you can quickly delete the rows with certain cell value, please do as the following steps:
1. Press the Alt + F11 keys at the same time to open Microsoft Visual Basic for applications window,
2. Click Insert > Module, and input the following code into the Module:
VBA: Remove entire rows based on cell value
Sub DeleteRows() 'Updateby20211217 Dim rng As Range Dim InputRng As Range Dim DeleteRng As Range Dim DeleteStr As String Dim xTitleId As String Dim xArr Dim xF As Integer Dim xWSh As Worksheet On Error Resume Next xTitleId = "KutoolsforExcel" Set rng = Application.Selection Set InputRng = Application.InputBox("Range :", xTitleId, rng.Address, Type:=8) If InputRng Is Nothing Then Exit Sub DeleteStr = Application.InputBox("Delete Text", xTitleId, Type:=2) Set xWSh = InputRng.Worksheet For Each rng In InputRng If rng.Value = DeleteStr Then If DeleteRng Is Nothing Then Set DeleteRng = rng Else Set DeleteRng = Application.Union(DeleteRng, rng) Set DeleteRng = DeleteRng.EntireRow End If End If Next xArr = Split(DeleteRng.AddressLocal, ",") DeleteRng.Select DeleteRng.Delete For xF = UBound(xArr) To 0 Step -1 Set DeleteRng = xWSh.Range(xArr(xF)) DeleteRng.Delete Next End Sub
3. Then click the Run button to run the code.
4. In the popping up dialog box, please select the range where you will remove rows based on the certain value, and click the OK button.
5. In another dialog box, please type the certain value you will remove rows based on, and clicks the OK button. See screenshot:
And then you will see entire rows have been deleted based on the specified value already.
If you have installed Kutools for Excel, its Select Specific Cells feature can help you quickly delete the rows with specific value. Please do as follows:
2. In the opening Select Specified Cells dialog box, please check Entire row option, select Contains from Specific type drop down list, enter the specified value into right box, and click the Ok button (See above screenshot).
After applying this feature, a dialog box will pop out and show you how many cells have been found based on the specified criteria. Please click the OK button to close it.
3. Now entire rows with the certain value are selected. Please right click the selected rows, and click the Delete from the right-clicking menu. See screenshot below:
Note: This Select Specific Cells feature supports to delete rows by one or two certain values. For deleting rows based on two specified values, please specified another value in the Specific type section of Select Specific Cells dialog box as following screenshot shown:
In some cases, you may need to remove rows based on multiple cell values from another column/list in Excel. Here I will introduce Kutools for Excel's Select Same & Different Cells feature to solve it quickly with ease.
2. In the opening Select Same & Different Cells dialog box, please do as follows (see screenshot):
(1) In the Find values in box, please select the column where you will find the certain values;
(2) In the According to box, please select the column/list with multiple values you will delete rows based on;
(3) In the Based on section, please check the Each row option;
(4) In the Find section, please check the Same Values option;
(5) Check the Select entire rows option at the bottom of opening dialog box.
Note: If two specified columns contain the same header, please check the My data has headers option.
3. Click the Ok button to apply this utility. And then a dialog box comes out and shows how many rows have been selected. Just click the OK button to close it.
And then all rows containing values among the specified list have been selected.
4. Click Home > Delete > Delete Sheet Rows to delete all selected rows.
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!