VBA delete entire row if a cell is blank

Anonymous
2016-08-21T18:19:41+00:00

Hi,

i want to delete the entire row when a cell within the row is blank.

So ,I tried it but the below code is not working.

Sub DeleteAllBlankCells()

    Windows("Form.xlsm").Activate

    Sheets("Sheet1").Select

    Cells.Select

    Selection.EntireRow.SpecialCells(xlBlanks).EntireRow.Delete

End Sub

You can download the workbook by Clicking here.

Thank You!

Regards

Wither

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2016-08-27T16:01:14+00:00

    > ... You'll have to loop through the columns."

    Sub DeleteRowsWithBlanks()

        Dim Rng As Range

        On Error Resume Next ' In case there are no blanks

        Set Rng = [A:V].SpecialCells(xlCellTypeBlanks).EntireRow

        Intersect(Rng, Rng).Delete

        ActiveSheet.UsedRange 'Reset

    End Sub

    1 person found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2016-08-27T15:42:20+00:00

    Try this version:

    Sub DeleteAllBlankCells()

        Dim r As Long

        Dim m As Long

        Application.ScreenUpdating = False

        m = Range("A:V").Find(What:="*", SearchOrder:=xlByRows, _

            SearchDirection:=xlPrevious).Row

        For r = m To 2 Step -1

            If Application.CountIf(Range("A" & r & ":V" & r), "") > 0 Then

                Range("A" & r).EntireRow.Delete

            End If

        Next r

        Application.ScreenUpdating = True

    End Sub

    1 person found this answer helpful.
    0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Anonymous
    2017-07-26T15:38:51+00:00

    Did as instructed, but when I press F5 I get "Syntax Error" and it highlights the first line "Dim r As Long".

    0 comments No comments
  2. HansV 462.4K Reputation points MVP Volunteer Moderator
    2017-07-26T18:26:55+00:00

    That is weird - I have tested the code. Try copying and pasting the code into Notepad first, then copy it from there and paste it into the code module.

    0 comments No comments
  3. Anonymous
    2017-07-26T19:55:47+00:00

    Thank you!  That did the trick!

    0 comments No comments