0

i have an issue where deleting a selected row, deletes the row selected, but the "Total Row" merges with the table and I'm unable to do anything in the excel sheet and have to reset my progress.

I was wondering if someone can take a look at my code when deleting a table and let me know if they see anything wrong. I also attached the error message I receive before I'm unable to do anything with the spreadsheet.

Sub DeleteRow()
Dim rng As Range
On Error Resume Next
With Selection.Cells(1)
    Set rng = Intersect(.EntireRow, ActiveCell.ListObject.DataBodyRange)
    On Error GoTo 0
    If rng Is Nothing Then
        MsgBox "Please select a valid table cell.", vbCritical
    Else
        rng.Delete xlShiftUp
    End If
End With
End Sub

enter image description here

MSauce
  • 123
  • 2
  • 13
  • Have you tried the [`ListRows.Delete`](https://msdn.microsoft.com/en-us/vba/excel-vba/articles/listrow-object-excel)? – PatricK May 07 '18 at 05:26
  • How can your totals row be merged with your table, if you are unable to delete the row? – Luuklag May 07 '18 at 06:55
  • @PatricK I attempted to insert rng.ListRows.Delete but it would not run. – MSauce May 07 '18 at 11:43
  • My bad putting the `s` there. if you open the link there you find more information on the `ListRow`, and the [`ListRows` Collection object](https://msdn.microsoft.com/en-us/vba/excel-vba/articles/listrows-object-excel) Basically you need to find the ListRow from the ListRows collection to Delete. – PatricK May 07 '18 at 23:38

0 Answers0