REAL-TIME

VBA Projects

Full Access with Source Code
  • Designed and Developed by PNRao

  • Full Access with VBA Source Code

  • Well Commented Codes Lines

  • Creative and Professional Design

Effortlessly
Manage Your Projects

120+ Project Management Templates

Seamlessly manage your projects with our powerful & multi-purpose templates for project management.

120+ PM Templates Includes:
  • 50+ Excel Templates

  • 50+ PowerPoint Templates

  • 25+ Word Templates

Share Post

VBA code to delete blank rows in table example will helps to delete empty rows in specific table range from excel worksheet. We can use Delete method of Rows to delete the rows in a table. In this example we will see how to delete the rows from a table in excel worksheet using VB. Excel VBA Macro code for deleting rows in a table should work for all the version of Microsoft Excel 2003, Excel 2007, Excel 2010, and Excel 2013.

VBA delete blank rows in table Excel Macro Example Code

VBA code to delete rows in a table


Here is the Example VBA syntax and Example VBA Macro to delete rows in table from excel worksheets. This will help you to know how to delete specific rows in a table from Excel workbook using VBA.

VBA delete blank rows in table: Syntax


Following is the VBA syntax and sample VBA code to delete rows in a table from worksheet using VBA. We are using the Delete method of the Rows object of worksheet.


If Application.WorksheetFunction.CountA(Rows(RowNumber)) = 0 Then Rows(RowNumber).EntireRow.Delete

Here Application.WorksheetFunction.CountA will check if the row is blank. And the Rows.delete method will delete the row if row is blank.

Delete blank rows in Table: Examples


The following VBA code is to delete blank rows in Table1 in the active sheet if rows are blank.

Sub sbVBS_To_Delete_Blank_Rows_In_Table()
Dim iCntr As Long
Dim rng As Range

Set rng = ActiveSheet.ListObjects("Table1").Range

For iCntr = rng.Row + rng.Rows.Count - 1 To rng.Row Step -1
        If Application.WorksheetFunction.CountA(Rows(iCntr)) = 0 Then Rows(iCntr).EntireRow.Delete
    Next
End Sub 

Instructions to run the VBA code to delete blank rows in table


Please follow the below steps to execute the VBA code to delete blank rows in Table1 from Excel worksheets.
Step 1: Open any Excel workbook
Step 2: Press Alt+F11 – This will open the VBA Editor
Step 3: Insert a code module from then insert menu
Step 4: Copy the above code and paste in the code module which have inserted in the above step
Step 5: Enter some sample data and insert table. And leave some blank rows for testing purpose.
Step 6: Now press F5 to execute the code

Now you can observe that the all blank rows are deleted from worksheet in in Table1.

Explained VBA Code to Delete Rows in Table


‘Start writing the Excel VBA Macro to delete blank rows in a particular range
Sub sbVBS_To_Delete_Blank_Rows_In_Table()

‘Declaring a variable iCntr as Long to store the row number iteration to use in for loop.
Dim iCntr As Long
‘Declaring range variable rng to set the range
Dim rng As Range

‘Assigning the range A10 to D20 to rng range object
Set rng = ActiveSheet.ListObjects(“Table1”).Range

‘Looping through the rows in the table tange from last to frist. Here step statement will helps.
For iCntr = rng.Row + rng.Rows.Count – 1 To rng.Row Step -1
‘Checking the row if it is blank.
‘And deleting the row if it is blank.
If Application.WorksheetFunction.CountA(Rows(iCntr)) = 0 Then Rows(iCntr).EntireRow.Delete
Next

End Sub
Ending the sub procedure to delete blank rows in a table range.

Effortlessly Manage Your Projects and Resources
120+ Professional Project Management Templates!

A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.

Save Up to 85% LIMITED TIME OFFER
Project Management Templates

All-in-One Pack
120+ Project Management Templates

Essential Pack
50+ PM Templates

Excel Pack
50+ Excel PM Templates

PowerPoint Pack
50+ Excel PM Templates

MS Word Pack
25+ Word PM Templates

Ultimate Project
Management Template
Ultimate Resource
Management Template
Project Portfolio
Management Templates
Categories: VBATags: Last Updated: June 17, 2022

3 Comments

  1. rd November 13, 2014 at 1:39 PM

    great article. I needed a refresher. Thanks..

  2. Al K February 20, 2015 at 1:58 AM

    My VBA Editor shows that

    For iCntr = rng.Row + rng.Rows.Count – 1 To rng.Row Step -1

    has Compile Error: Syntax error

  3. Frej Lindström August 30, 2018 at 6:50 PM

    Hi,

    If you are using ListObjects as a Table, then I believe this is easier to interpret.

    Sub RemoveBlankRow(ByVal SheetName As String, TableName As String)
    Dim rng As Integer

    rng = Sheets(SheetName).ListObjects(TableName).DataBodyRange.Rows.Count

    For i = 1 To rng
    If Application.WorksheetFunction.CountA(Rows(i)) = 0 Then Rows(i).EntireRow.Delete
    Next
    End Sub

Leave A Comment