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.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,505
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.
 

Forum statistics

Threads
1,081,523
Messages
5,359,263
Members
400,523
Latest member
ExcelNewbie98

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top