I want to delete the cells selected in the table. Error occurs when I Delete a mid row of the table.
any help/fix/improvement is appriciated!
VBA Code:
Sub DeleteTableMember()
Application.ScreenUpdating = False
On Error Resume Next
If ActiveSheet.ListObjects(1) Is Nothing Then Exit Sub
If ActiveSheet.ListObjects(1).DataBodyRange Is Nothing Then Exit Sub
Dim COLUMN_FIRSTCOLUMN As Integer
COLUMN_FIRSTCOLUMN = ActiveSheet.ListObjects(1).DataBodyRange(1, 1).Column
On Error GoTo 0
Dim tmpCell As Range
Dim delRng As Range
For Each tmpCell In Selection
If Not Intersect(tmpCell, ActiveSheet.ListObjects(1).DataBodyRange) Is Nothing Then
If delRng Is Nothing Then
Set delRng = Cells(tmpCell.Row, COLUMN_FIRSTCOLUMN)
Else
Set delRng = Union(Cells(tmpCell.Row, COLUMN_FIRSTCOLUMN), delRng)
End If
End If
Next tmpCell
If delRng Is Nothing Then Exit Sub
Dim i As Integer
For i = ActiveSheet.ListObjects(1).ListRows.Count To 1 Step -1
If Not Intersect(ActiveSheet.ListObjects(1).DataBodyRange(i, 1), delRng) Is Nothing Then
ActiveSheet.ListObjects(1).ListRows(i).Delete
End If
Next i
Application.ScreenUpdating = True
End Sub
any help/fix/improvement is appriciated!