How to remove multiple empty lines in a table

F

Francis4344

Sure, you can select and remove a line but this table was generated from an
Wp document with an empty line at every other line...

Any way of telling Word, either through a macro or otherwise, to remove all
empty lines?
 
J

Jezebel

Easy enough to write a macro to do it, if you know how to write macros.
Depending on what your rows contain, you could also simply sort the table:
then the empty rows come together and you can delete them in one action.
 
A

Access101

And if you want to maintain the same order as the original, just add a
column, auto number it, and then resort after the deletions
 
K

Klaus Linke

And if you want to maintain the same order as the original, just add a

Suzanne S. Barnhill said:
Auto numbering will be updated when you sort, so it won't help much.

SEQ fields won't unless you update fields, and it's pretty easy to put one
into an otherwise empty column (... copy the field, select column, paste).

Klaus
 
K

Kon

I think that you are talking about excel, not word. I was wondering how to
do it in word by vba for some time now and would appreciate help:)
 
M

macropod

Hi Kon,

The following code will delete all blank rows (except for those with vertically merged cells) in all tables in the active document:

Sub DelBlankRows()
Dim Pwd As String
Dim oRow As Integer
Dim oTable As Table
Dim pState As Boolean
With ActiveDocument
pState = False
If .ProtectionType <> wdNoProtection Then
Pwd = InputBox("PleasePassword", "Password")
pState = True
.Unprotect Pwd
End If
If .Tables.Count > 0 Then
For Each oTable In .Tables
For oRow = oTable.Rows.Count To 1 Step -1
If Len(Replace(oTable.Rows(oRow).Range.Text, Chr(13) & Chr(7), vbNullString)) = 0 Then
On Error Resume Next 'skip vertically merged cells
oTable.Rows(oRow).Delete
End If
Next oRow
Next oTable
End If
If pState = True Then .Protect wdAllowOnlyFormFields, Noreset:=True, Password:=Pwd
pState = False
Pwd = ""
End With
End Sub

If the document is protected for forms, you'll need to replace "Password" with the real password (if any)

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top