Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Aug 2003
    Location
    Baltimore, Maryland, USA
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    tables-delete all empty rows (Word 2K, SR1)

    I get a lot of Excel files to bring into Word as tables. Most of the Excel files have empty rows and I used to be able to filter out blanks, then copy them over. Now I can't always filter out blanks because of the way data is laid out. Some of these worksheets go 2000 lines with maybe 250 blank rows. So I hope someone can tell me if there's a way to delete all empty rows in a table. I figure it would have to be a macro, but I wouldn't even know where to start. Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: tables-delete all empty rows (Word 2K, SR1)

    Here is such a macro. It will fail if there are vertically merged cells in the table. Place the insertion point in the table to be processed before running the macro.

    Sub DeleteEmptyRowsFromTable()
    Dim tbl As Table
    Dim i As Long
    Dim n As Long
    Dim cel As Cell
    Dim fEmpty As Boolean

    On Error GoTo ErrHandler

    If Not Selection.Information(wdWithInTable) Then
    MsgBox "Place insertion point within table"
    Exit Sub
    End If

    Set tbl = Selection.Tables(1)
    n = tbl.Rows.Count
    For i = n To 1 Step -1
    fEmpty = True
    For Each cel In tbl.Rows(i).Cells
    If Len(cel.Range.Text) > 2 Then
    fEmpty = False
    Exit For
    End If
    Next cel
    If fEmpty Then
    tbl.Rows(i).Delete
    End If
    Next i

    ExitHandler:
    Set cel = Nothing
    Set tbl = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  3. #3
    Lounger
    Join Date
    Aug 2003
    Location
    Baltimore, Maryland, USA
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: tables-delete all empty rows (Word 2K, SR1)

    Thanks Hans. Boy, will this save a lot of time!!

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: tables-delete all empty rows (Word 2K, SR1)

    Another option might be to simply sort the table in Word (though I've never tried sorting a 2000-row table). If you can do this, it should be possible to put the empty rows at the top or bottom of the table.

Posting Permissions

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