Find Blank Cells in 2 Columns The Delete Entire Row

dgr

Board Regular
Joined
Apr 24, 2005
Messages
176
Hi,
I'm using Excel 2013. I'm looking for a VBA macro solution.

I want to find blank cells in column G and column N. If the cells in both these columns are empty, I want to delete the entire row. How do I do this via a macro?

The logic is explained below.

Cell g13 is blank, cell n13 is blank. Therefore delete row 13.
Cell g25 contains data, cell n25 is blank. Don't do anything (move on to the next row).
Cell g4 contains data, cell n4 contains data. Don't do anything (move on to the next row).

Therefore, the logic is if either one or both cells in column G and column N along the same row contain data, don't do anything. If both cells in column G and column N along the same row are blank, delete that row.

Could you show me the code please?

Thanks.
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,986
Try:
Code:
Sub DelRows()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim x As Long
    For x = LastRow To 1 Step -1
        If Cells(x, "G") = "" And Cells(x, "N") = "" Then
            Rows(x).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = True
End Sub
 

dgr

Board Regular
Joined
Apr 24, 2005
Messages
176
Thanks a lot mumps. This was exactly what i was looking for. i appreciate your help. Have a good day.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,876
Messages
5,574,765
Members
412,617
Latest member
mlharris
Top