Question: I need to delete specific rows in a table with a order number. When I put this code in Excel it delete the entire table. What I want is to delete only specific rows. The tbxOrder is a text box. I want that when the text box equals x command number the code will select all the rows with the same number in the "Pagination" table (column 20) and then delete them. Thank you :)

```
Public Sub DeleteOrderRows()

Dim strNoOrder As String
Dim strNoFunction As String
Dim noCommande As Integer

Dim tblPagination As ListObject
Set tblPagination = Worksheets("Pagination").ListObjects.Item("tblPagination")

For Each srcrow In tblPagination.ListRows

strNoOrder = srcrow.Range.Cells(1, 20)
noOrder = tbxOrder.Value

If strNoOrder = noOrder Then

EntireRow.Delete

End If

Next

End Sub

```

Answer: 
Try it without the ListRows; use DataBodyRange instead. Work from the bottom to the top or you risk skipping rows when you delete.

```
Option Explicit

Public Sub DeleteOrderRows()

    Dim strNoOrder As String
    Dim strNoFunction As String, noOrder As String
    Dim noCommande As Integer
    Dim i As Long, tbxOrder As Range
    Dim tblPagination As ListObject

    Set tblPagination = Worksheets("Pagination").ListObjects.Item("tblPagination")

    'here I had to set tbvOrder and assign noOrder
    Set tbxOrder = Worksheets("Pagination").Cells(1, "A")
    noOrder = tbxOrder.Value

    With tblPagination.DataBodyRange.Columns(20).Cells
        For i = .Count To 1 Step -1
            Debug.Print .Cells(i).Address(0, 0)
            strNoOrder = .Cells(i).Value2

            If strNoOrder = noOrder Then
                .Cells(i).EntireRow.Delete
            End If

        Next i
    End With

End Sub

```
An other option :

```
Public Sub DeleteOrderRows()
Dim rngToDelete As Range
Set rngToDelete = Nothing

Dim tblPagination As ListObject
Set tblPagination = Worksheets("Pagination").ListObjects.Item("tblPagination")

Dim strNopage As String
Dim strNoOrder As String

For Each currentRow In tblPagination.ListRows
    strNoOrder = currentRow.Range.Cells(1, 5).Value
    strNopage = tbxPage.Value
    If strNoCommande = strNopage Then
        If rngToDelete Is Nothing Then
            Set rngToDelete = currentRow.Range
        Else
            Set rngToDelete = Union(rngToDelete, currentRow.Range)
        End If
    End If
Next

If Not rngToDelete Is Nothing Then
    rngToDelete.Delete Shift:=xlUp
End If

End Sub

```