How to Delete an Entire Row if a Cell Contains Zero in Excel


Excel is a strong data manipulation and analysis tool, and being able to manage large datasets efficiently is critical. Deleting rows based on specified criteria, such as the existence of specific values, can greatly simplify your data cleaning procedure. This article will walk you through the process of identifying and eliminating rows with zero values in a specific cell. This method is especially useful when working with huge datasets, when identifying and removing certain values is critical for correct analysis and reporting.

This tutorial will teach you a simple and effective approach for automating the deletion of rows depending on particular criteria, saving you time and effort. So, let's get started with this Excel tutorial and see how to erase complete rows with zero data!

Delete Entire Row If Cell Contains Zero

Here we will first create a VBA module, then run it to select the column range you want to delete to complete the task. So let us see a simple process to know how you can delete an entire row if a cell contains zero in Excel.

Step 1

Consider an Excel sheet where the data in the sheet is similar to the below image.

First, right-click on the sheet name and select "View Code" to open the VBA application.

Right click > View code.

Step 2

Then click on Insert, select Module, and copy the below code into the text box.

Insert > Module > Ok.

Example

Sub DeleteZeroRow()
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Delete Row Contain"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Do
   Set Rng = WorkRng.Find("0", LookIn:=xlValues)
   If Not Rng Is Nothing Then
      Rng.EntireRow.Delete
    End If
Loop While Not Rng Is Nothing
Application.ScreenUpdating = True
End Sub  

Step 3

Then click F5 to run the code, select the column range you want to delete rows from, and click OK to complete the task.

F5 > Select cells > Ok.

Conclusion

In this tutorial, we have used a simple example to demonstrate how you can delete an entire row if a cell contains zero in Excel to highlight a particular set of data.

Updated on: 12-Jul-2023

85 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements