DELETING BLANK ROWS

  • Thread starter Thread starter Faraz A. Qureshi
  • Start date Start date
F

Faraz A. Qureshi

Can one of you experts kindly devise a macro for me so as to have from all
the tables from the text copied to a word document from a web page, blank
rows deleted.

There are different tables at different locations/pages.

Thanx in advance.
 
The following should work. Rows with merged cells will be ignored.

Sub DeleteBlankRows()
Dim oRow As Range
Dim iCount As Integer
With ActiveDocument
For i = .Tables.Count To 1 Step -1
For j = .Tables(i).Rows.Count To 1 Step -1
Set oRow = .Tables(i).Rows(j).Range
iCount = (oRow.Columns.Count * 2) + 2
If Len(oRow) = iCount Then
.Tables(i).Rows(j).Delete
End If
Next j
Next i
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
By the way I have found that some of the cells are found to be consisting
only spaces.

How to carryout the exercise for such cells with only spaces?
 
If some cells only contain spaces, then you need to test each cell to remove
the spaces before testing the rows eg

Sub DeleteBlankRows()
Dim oRow As Range
Dim oCell As Cell
Dim oRng As Range
Dim iCount As Integer
With ActiveDocument
For i = .Tables.Count To 1 Step -1
For j = .Tables(i).Rows.Count To 1 Step -1
Set oRow = .Tables(i).Rows(j).Range
For k = 1 To .Tables(i).Columns.Count
Set oRng = .Tables(i).Cell(j, k).Range
oRng.End = oRng.End - 1
For l = oRng.Characters.Count To 1 Step -1
If oRng.Characters(l) = Chr(32) Then
oRng.Characters(l).Delete
Else
GoTo NextCell
End If
Next l
NextCell:
Next k
iCount = (oRow.Columns.Count * 2) + 2
If Len(oRow) = iCount Then
.Tables(i).Rows(j).Delete
End If
Next j
Next i
End With
End Sub

This macro will produce an error with merged cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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

Back
Top