VBA Delete Blank Row From an Excel Table

ManUBlueJay

Active Member
Joined
Aug 30, 2012
Messages
302
Office Version
  1. 2016
Platform
  1. Windows
I have a table on Sheet 1 called Table1.

The Table is 9 Columns wide and very long

Is there a simple VBA code that looks at this table and if the the whole row is blank it deletes the whole row from that table.
It Cannot delete the entire row of the worksheet as there is another table on that sheet.
It is not a one time exercise so I am trying to automate it
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Something like this

VBA Code:
Sub JEC()
 With Sheets(1).ListObjects(1)
    For i = .ListRows.Count To 1 Step -1
      If Len(Trim(Join(Application.Transpose(Application.Transpose(.ListRows(i).Range))))) = 0 Then .ListRows(i).Delete
    Next
 End With
End Sub
 
Last edited:
Upvote 0
Try this:

VBA Code:
Sub DeleteRowInTable()
  Dim lo As ListObject
  Dim r As Long
  Set lo = ActiveSheet.ListObjects("Table1")
  For r = lo.DataBodyRange.Rows.Count To 1 Step -1
    With lo.DataBodyRange.Rows(r)
      If WorksheetFunction.CountA(.Value) = 0 Then .Delete
    End With
  Next
End Sub
 
Upvote 0
Didn't think of Counta, easier :)

VBA Code:
Sub JEC()
 With Sheets(1).ListObjects(1)
    For i = .ListRows.Count To 1 Step -1
      If Application.CountA(.ListRows(i).Range) = 0 Then .ListRows(i).Delete
    Next
 End With
End Sub
 
Upvote 0
Solution
I just managed to get this to work, or is this a slow way.
It looks at the Col called Element which is always empty if the whole row is empty

VBA Code:
Sub DeleteBlanks()

With Worksheets("Sheet1").ListObjects("Table1")
     .ListColumns("Element").DataBodyRange.SpecialCells(xlCellTypeBlanks).Rows.Delete
End With

End Sub
 
Upvote 0
Hello,

my problem is a bit similar. my table headers are in c30:k30 and i am using the attached code to paste some data in the table. what i am looking for is a code to add to it that would run after my data pasting code (code will be added to the existing macro) and then delete table rows having all blank cells.

thank you

KF

VBA Code:
Sub Create_Entry()
'
' Create_Entry Macro
'
' Keyboard Shortcut: Ctrl+a
'

Application.ScreenUpdating = False


With ActiveSheet
      .Unprotect "7860"


Range("E10").Select
    Selection.Copy
    Range("A10").Select
    ActiveWindow.LargeScroll Down:=1
    Range("A37").Select
    ActiveWindow.LargeScroll Down:=1
    Range("A64").Select
    ActiveWindow.LargeScroll Down:=1
    Range("A91").Select
    Selection.End(xlDown).Select
    Range("A5001").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveWindow.ScrollRow = 4989
    ActiveWindow.ScrollRow = 4909
    ActiveWindow.ScrollRow = 3
    ActiveCell.Offset(-5001, 4).Range("A1").Select





    Range("D10:G10").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("D31").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range("D31").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("E10").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("F10:G13").Select
    Selection.ClearContents
    
 

 

  Range("E10").Select



    .Protect "7860"

End With

    
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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