Delete Entire Row when two cells are blank

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,

Data is entered into range A9 to L (row unknown as data keeps being added). I would like a macro to delete the entire row if BOTH the cells in column E and F are blank. If only one is blank, it shouldn't be deleted.
I'm not really hitting the mark so far with my code.

Sub Delete_Blank_Rows()
On Error Resume Next
ActiveSheet.Columns("E").SpecialCells(xlBlanks).EntireRow.Delete
End Sub

This deletes all rows only if column E is blank.

Can someone help me please?

Thank you.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Code:
Sub Delete_Blank_Rows()

Dim sht As Worksheet
Dim LastRow As Long
Dim rownum As Long


Set sht = ActiveSheet


rownum = 9
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row


Do Until rownum = LastRow + 1
If Cells(rownum, 5) = "" And Cells(rownum, 6) = "" Then
Rows(rownum).Delete
rownum = rownum - 1
End If
rownum = rownum + 1
Loop


End Sub
 
Last edited:
Upvote 0
this code works for me....

Code:
    'delete blank lines
    Application.ScreenUpdating = False
    For LR = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
        If Range("A" & LR).Value = "" Or Left(Range("A" & LR), 1) = "`" Then
            Rows(LR).EntireRow.Delete
        End If
    Next LR

it deletes any row with a blank cell in column A, it also deletes any row with ` symbol in column A
 
Upvote 0
As per VBA when trying to use two or more columns with Special Cells:

"Cannot use that command on overlapping selections"

If your data set isn't too large you could loop backwards through it deleting each row where Col's E and F are blank like so:

Code:
Option Explicit
Sub Delete_Blank_Rows()

    Dim lngLastRow As Long
    Dim lngMyRow As Long
    Dim xlnCalcMethod As XlCalculation
    
    With Application
        .ScreenUpdating = False
        xlnCalcMethod = .Calculation
        .Calculation = xlCalculationManual
    End With
    
    lngLastRow = Range("A:L").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    'Work backwards through the rows from the last row found to Row 9.
    For lngMyRow = lngLastRow To 9 Step -1
        If Len(Range("E" & lngMyRow)) = 0 And Len(Range("F" & lngMyRow)) = 0 Then
            Rows(lngMyRow).EntireRow.Delete
        End If
    Next lngMyRow
    
    With Application
        .Calculation = xlnCalcMethod
        .ScreenUpdating = True
    End With
    
End Sub

HTH

Robert
 
Last edited:
Upvote 0
sorry.... i just noticed what you are asking and my code isn't helpful at all lol.... sorry.

this code works for me....

Code:
    'delete blank lines
    Application.ScreenUpdating = False
    For LR = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
        If Range("A" & LR).Value = "" Or Left(Range("A" & LR), 1) = "`" Then
            Rows(LR).EntireRow.Delete
        End If
    Next LR

it deletes any row with a blank cell in column A, it also deletes any row with ` symbol in column A
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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