Delete entire row if contains number

How to delete an entire row if a number is contained in a selected range using Excel and VBA methods

METHOD 1. Delete entire row if contains number

EXCEL

Enter formula in the column next to the last data column > Apply the formula across relevant rows > Select the range, including the formula > Home tab > Editing group > Click Sort & Filter > Click Filter > Filter for Number > Select all the rows within the range > Editing > Click Find & Select > Click Go To Special > Select Visible cells only > Click OK > Delete rows

In this example we will be deleting entire rows if there is a number in any of the rows, in range (B3:E8). This image shows the starting point without any adjustments. Original values without adjustments

1. Scroll to the column next to the last data column, which in this example will be column F. Enter this formula into the column against the first data row (=IF(SUMPRODUCT(--ISNUMBER(data_row_rng))>0,"Number","No Number")). The data_row_rng is a range that represents a single row from a data range that you are testing for numbers.
2. Apply the formula across all of the rows associated with the range.
Note: in this example we are applying the formula for rows 3 to 8.
We have also inserted a column heading, Number/No Number, in cell F2 associated with formula that is applied.
Enter formula

3. Select the data range, including the formula and the associated headings.
Note: in this example we are selecting range (B2:F8).
Select range including formula

4. Select the Home tab. Select Home tab - Excel 2016

5. Click on Sort & Filter in the Editing group.
6. Click on Filter.
Click Sort and Filter and click Filter

7. Filter for Number by clicking of the filter box in the Number/No Number cell (F2) and selecting only the Number checkbox.
8. Click OK.
Filter for Text

9. Select all of the rows in the data (filtered) range.
Note: in this example we are selecting rows 3 to 8.
Select entire rows filtered

10. Click on Find & Select in the Editing group.
11. Click on Go To Special.
Click Find & Select and click Go To Special

12. Select Visible cells only.
13. Click OK.
Select Visible cells only and click OK

14. Delete visible rows.
Note: to delete the visible rows, right-click on any of the selected cells and click Delete row.
Delete filtered rows

This image shows the final outcome of the process explained above. All of the rows in range (B3:E8) that contained a number have been deleted. Final outcome

METHOD 1. Delete entire row if contains number using VBA

VBA

Sub Delete_entire_row_if_contains_number()
'declare variables
Dim ws As Worksheet
Dim iRow As Integer
Set ws = Worksheets("Analysis")
'delete rows with a number in a single column by looping through relevant rows
For iRow = ws.Range("B3:B8").Rows.Count To 1 Step -1

If Application.WorksheetFunction.IsNumber(Cells(iRow + 2, 2)) = True Then
ws.Cells(iRow + 2, 2).EntireRow.Delete
End If

Next

End Sub

OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named Analysis.
Data Range: This VBA code assumes that all of the data in the worksheet is contained in range (B3:B8), therefore, all data is captured in one column.
ADJUSTABLE PARAMETERS
Data Range: Select the data range by changing the column reference number from 2 and the row range by changing the range associated with iRow (B3:B8).

ADDITIONAL NOTES
Note 1: This VBA code assumes that all of the data is stored in column B.

Explanation about how to delete entire rows that contain a number

EXPLANATION

EXPLANATION
This tutorial explains and provides step by step instructions on how to delete entire rows if any of the cells in the selected range contain a number (cell treated as a numeric value), using an Excel and VBA method.

Excel Method: Using Excel you can delete entire rows that contain a number by initially identifying the rows that contain a number, using this formula =IF(SUMPRODUCT(--ISNUMBER(data_row_rng))>0,"Number","No Number"). Then you would filter for only the rows that contain a number and delete the rows. The data_row_rng represents a single row range that you are testing if it contains a number.

VBA Method: The VBA method uses the For Loop to loop through each specified row, which is row 3 through to row 8 in column B and delete any row that contains a number.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to delete an entire row if text is contained in a selected range using Excel and VBA methods