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.
We want to remove those records which contain blank cells.
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.
Set Rng = Range("A9:C" & LastRow)
The above code is used to create a range object for the given data.
The above code is used to select blank cells within the specified range.
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
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 email@example.com
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.