none
Word Table Macro to Delete End of Rows

    Question

  • I have a Word 2007 table with many rows that have words in the rows, and below each row with words there is a blank row....but below the last row that has words in it, there are many many rows that have not words in them...meaning blank rows.....so I need a macro if possible that simply deletes the blank rows that are below the last roll that has words in it..

    Thanks very much!

    Tuesday, November 19, 2013 4:55 PM

Answers

  • Try:

    Sub DelEndBlankRows()
    Dim i As Long, j As Long
    With ActiveDocument
      For i = .Tables.Count To 1 Step -1
        For j = .Tables(i).Rows.Count To 1 Step -1
          With .Tables(i).Rows(j)
            If Len(.Range.Text) = 2 * .Cells.Count + 2 Then
              .Delete
            Else: Exit For
            End If
          End With
        Next
      Next
    End With
    End Sub

    To delete all the blank rows, not just the last ones, simply omit 'Else: Exit For'


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, November 20, 2013 6:34 AM

All replies

  • Try:

    Sub DelEndBlankRows()
    Dim i As Long, j As Long
    With ActiveDocument
      For i = .Tables.Count To 1 Step -1
        For j = .Tables(i).Rows.Count To 1 Step -1
          With .Tables(i).Rows(j)
            If Len(.Range.Text) = 2 * .Cells.Count + 2 Then
              .Delete
            Else: Exit For
            End If
          End With
        Next
      Next
    End With
    End Sub

    To delete all the blank rows, not just the last ones, simply omit 'Else: Exit For'


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, November 20, 2013 6:34 AM
  • It worked perfect! Thank- you. Just in case you know, I paste to the word document a table from outlook from the note field of a contact, and then the word document automatically runs for the word table which is two columns and many rows, that fonts the words, extends the width of the rows, deletes all empty rows, and then puts an empty row after each two rows, and then uses the macro you gave me, so it fixes the table, I copy it and then paste it to the calemdar event body of the contact. So if I paste the original table from the outlook contact note field to the calendar event body, can I identify the table and use the word macros to adjust the table as if it is in the word document? Be great if that can be done! Thanks so much.
    Thursday, November 21, 2013 3:41 AM