Results 1 to 2 of 2

Thread: deleting rows in word table if certain cells are empty or contain a specific value

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Jan 2022

    deleting rows in word table if certain cells are empty or contain a specific value

    I have this code (attached below) which will delete the rows in a word table if all the cell rows are empty.

    However I have a table with eight columns, the first four of which will always contain text. The latter four contains data linked to an excel document.

    The question is; how do I get the code to search through the latter four (data) columns and IF the columns are empty and/or contain a value (such as zero) THEN delete the row.

    Any help will be much appreciated.

    Thanks in advance

    Sub DeleteBlankRowsAndTablesInATable()
      Dim objCell As Cell
      Dim nRowIndex As Integer, nRows As Integer, nColumns As Integer, nColumnIndex As Integer
      Dim varCellEmpty As Boolean
      Application.ScreenUpdating = False
      If Selection.Information(wdWithInTable) = False Then
        MsgBox ("Put cursor inside a table first!")
        Exit Sub
        With Selection.Tables(1)
          nRows = .Rows.Count
          For nRowIndex = nRows To 1 Step -1
            varCellEmpty = True
            For Each objCell In .Rows(nRowIndex).Cells
              If Len(objCell.Range.Text) > 2 Then
                varCellEmpty = False
                Exit For
              End If
            Next objCell
              If varCellEmpty = True Then
              End If
          Next nRowIndex
        End With
      End If
      Set objCell = Nothing
      Application.ScreenUpdating = True
    End Sub

  2. #2
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts