View Single Post
 
Old 01-11-2024, 06:17 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 293
vivka is on a distinguished road
Default

Try copy-pasting the updated code again. I've checked it and it runs smoothly. I've imroved the code: now you can select the table and cell to start from:
Code:
Sub Del_Empty_Rows_If_3()
'In the doc's n-th tbl, delete rows if any (at least one) of their cell
'starting from the 3rd cell is empty.

Dim tbl As Table, tblNo As Long, cel As cell, cellNo As Long
Dim i As Long, j As Long, n As Long

    Application.ScreenUpdating = False
    tblNo = InputBox("Enter the table's number:")
    If tblNo > ActiveDocument.range.Tables.count Then
        MsgBox "There's no table with this number in this document."
        Exit Sub
    End If
    Set tbl = ActiveDocument.range.Tables(tblNo)
    cellNo = InputBox("Enter the cell's number to start from:")
    n = tbl.rows.count
    For i = n To 1 Step -1
        For j = cellNo To tbl.rows(i).Cells.count
            Set cel = tbl.rows(i).Cells(j)
            If Len(cel.range.text) = 2 Then
                tbl.rows(i).Delete
                Exit For
            End If
        Next j
    Next i
Set cel = Nothing: Set tbl = Nothing
Application.ScreenUpdating = True
End Sub
Reply With Quote