Delete table row if entire row is empty

Moluccanmom

New Member
Joined
Oct 13, 2016
Messages
41
Hello,

I am looking for a macro that deletes table rows that are completely empty.



Thank you,
Moluccanmom
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Assuming your table is on the active sheet.
And assuming your table is named: MyTable
Modify script to change Table name
Try this:
Code:
Sub Check_Table()
'Modified 4-19-18 5:35 AM EDT
Application.ScreenUpdating = False
Dim ans As Long
ans = ActiveSheet.ListObjects("MyTable").DataBodyRange.Rows.Count
With ActiveSheet.ListObjects("MyTable").DataBodyRange
    For i = ans To 1 Step -1
        ans = Application.WorksheetFunction.CountA(.Rows(i))
            If ans = 0 Then ActiveSheet.ListObjects("MyTable").DataBodyRange.Rows(i).Delete
        Next
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you, you are correct, my table is on the active sheet.
I pasted your code in a module and changed the table name in the code,
but my empty rows are still there, do you have an idea what I could be doing wrong?
Thanks!
 
Upvote 0
Code:
Sub Check_Table()'Modified 4-19-18 5:35 AM EDT
Application.ScreenUpdating = False
Dim ans As Long
ans = ActiveSheet.ListObjects("Data").DataBodyRange.Rows.count
With ActiveSheet.ListObjects("Data").DataBodyRange
    For i = ans To 1 Step -1
        ans = Application.WorksheetFunction.CountA(.Rows(i))
            If ans = 0 Then ActiveSheet.ListObjects("Data").DataBodyRange.Rows(i).Delete
        Next
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
See if this acts differently on your table
Code:
Sub DelTableRows()
  Dim i As Long
  
  Application.ScreenUpdating = False
  With ActiveSheet.ListObjects("MyTable").DataBodyRange
    For i = .Rows.Count To 1 Step -1
      If .Rows(i).Find(What:="?*", LookIn:=xlValues) Is Nothing Then
        .Rows(i).Delete
      End If
    Next i
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
I have no answer.
My script works for me.
Maybe you have spaces in your cells you cannot see.
 
Upvote 0

Forum statistics

Threads
1,214,524
Messages
6,120,049
Members
448,940
Latest member
mdusw

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