Delete Row if Cells in 3 columns are blank

pkew22

New Member
Joined
Aug 30, 2013
Messages
38
I would like to delete a row, if the cells in columns D, F, K of that row are blank. All three cells must be blank.

Columns A to W have data. Data (heading) starts in row 5. Number of rows varies

How do I do that?

Thank you.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Maybe something like this
Code:
Sub DeleteRows()
    For I = Range("A" & Rows.Count).End(xlUp).Row To 5 Step -1
        If Range("D" & I) = "" And Range("F" & I) = "" And Range("K" & I) = "" Then
            Rows(I).EntireRow.Delete
        End If
    Next I
End Sub
 
Upvote 0
Assuming the values in Column D are constants (that is, not formulas), give this macro a try...

Code:
Sub DeleteRowsIfCellsAreEmptyInColumnsDandFandK()
  Dim LastRow As Long
  LastRow = Cells.Find("*", , xlFormulas, , xlRows, xlPrevious).Row
  Range("[B][COLOR=#ff0000]D[/COLOR][/B]5:[B][COLOR=#ff0000]D[/COLOR][/B]" & LastRow) = Evaluate(Replace("IF(LEN(D5:D@&F5:F@&K5:K@)," & _
                            "IF(LEN([COLOR=#ff0000][B]D[/B][/COLOR]5:[COLOR=#ff0000][B]D[/B][/COLOR]@),[COLOR=#ff0000][B]D[/B][/COLOR]5:[B][COLOR=#FF0000]D[/COLOR][/B]@,""""),""#N/A"")", "@", LastRow))
  On Error Resume Next
  Columns("D").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  On Error GoTo 0
End Sub

If Column D has formulas, then use either F or K in place of the 6 red D's above depending on whether F or K are constants.
 
Upvote 0
Solution

Forum statistics

Threads
1,216,752
Messages
6,132,512
Members
449,731
Latest member
dasda34

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