Delete rows with blank cells in a certain column using VBA in Microsoft Excel

 

In this article, we will create a macro to delete incomplete records which contain blank cells.

Raw data consists of some sample data, which includes Name, Age and Gender. It also contains some blank cells.

ArrowRawData

We want to remove those records which contain blank cells.

ArrowOutput

Logic explanation

We have created “BlankRowDeletion” macro to delete incomplete records. It searches and selects blank cells and then deletes the entire row which contains a blank cell.

Code explanation

Set Rng = Range(“A9:C” & LastRow)

The above code is used to create a range object for the given data.

Rng.SpecialCells(xlCellTypeBlanks).Select

The above code is used to select blank cells within the specified range.

Selection.EntireRow.Delete

The above code is used to delete the entire row for the selected cell.

 

Please follow below for the code


Option Explicit

Sub BlankRowDeletion()

'Declaring variables
Dim LastRow As Long
Dim Rng As Range

'Getting row number of last cell
LastRow = Range("A1").SpecialCells(xlCellTypeLastCell).Row

'Selecting all data
Set Rng = Range("A9:C" & LastRow)

'Selecting Blank cells
Rng.SpecialCells(xlCellTypeBlanks).Select

'Deleting complete row
Selection.EntireRow.Delete

Range("A9").Select

End Sub

 

If you liked this blog, share it with your friends on Facebook. Also, you can follow us on Twitter and Facebook.

We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at info@exceltip.com



One thought on “Delete rows with blank cells in a certain column using VBA in Microsoft Excel

  1. “Consider the Following code to batch-delete the unused names in a workbook.

    Dim i As Integer

    For i = 1 To ActiveWorkbook.Names.Count
    ActiveWorkbook.Names(i).Delete
    Next i “

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>