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.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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
 
Upvote 0
Thanks a lot mumps. This was exactly what i was looking for. i appreciate your help. Have a good day.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,478
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top