0
votes

I have been looking around for an answer to this question for awhile now. I've found multiple great resources that show how to use a macro to delete a row if a cell within a specified column is blank but I haven't been able to find anything that will allow you to check a range of columns and delete a row if all cells in that range of columns is empty (if D1:F1 is entirely blank then delete row 1 but if in the range D2:F2 E2 has data in it don't delete that row).

Here's the code that I've been trying to mess around with

Application.ScreenUpdating = False
Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Application.ScreenUpdating = True

I found the above code from this answer Excel VBA: Delete entire row if cell in column A is blank (Long Dataset)

If I try and modify that code to say

Columns("D:F").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

I then get an error message which says "Run-time error 1004: Cannot use that command on overlapping sections."

1
Please do not assume we can watch your screen. Then I get an error when I try to run the code is not helpful. What error message do you get?user2261597
I edited my question to include the error message I got "Run-time error 1004: Cannot use that command on overlapping sections."joekeny
Either use AutoFilter or add a helper column to check the number of blanks (and then possibly use AF on that).SJR
So I have this in column G in my sheet =COUNTIF(D2:F2,"") how could I modify the code in my question to check column G for a specific number and delete that row if it matches?joekeny

1 Answers

0
votes

You have to do a bucle to loop through the columns because it doesn´t work if you have blank cells in more than one column on the same row.