A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Automate removal of blank rows from table



 
 
Thread Tools Display Modes
  #1  
Old January 8th, 2010, 05:55 PM posted to microsoft.public.word.tables
nhpaulao
external usenet poster
 
Posts: 1
Default Automate removal of blank rows from table

How do i delete blank rows from tables in an automated manner? My table is
200 pages and contains random blank rows due to another automated process,
and I want to be able to search/replace blank rows or somehow delete them.
  #2  
Old January 8th, 2010, 08:29 PM posted to microsoft.public.word.tables
Suzanne S. Barnhill
external usenet poster
 
Posts: 31,786
Default Automate removal of blank rows from table

If the table content is such that it can be sorted, then all blank rows will
sort to the top and can be easily deleted as a group. Barring that, you'll
need some sort of macro.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

"nhpaulao" wrote in message
...
How do i delete blank rows from tables in an automated manner? My table is
200 pages and contains random blank rows due to another automated process,
and I want to be able to search/replace blank rows or somehow delete them.


  #3  
Old January 8th, 2010, 10:36 PM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Automate removal of blank rows from table

If sorting is not an options, you can use the macro below:

Sub DeleteEmptyRows_AllTables()

Dim oTable As Table
Dim oRow As Row

For Each oTable In ActiveDocument.Tables
For Each oRow In oTable.Rows
'Check whether row is empty - delete if it is
If Len(oRow.Range.Text) = oRow.Cells.Count * 2 + 2 Then
oRow.Delete
End If
Next oRow
Next oTable

End Sub

How it works:
The macro iterates through all tables in the active document and finds (and
deletes) the empty rows by checking the total string length of each row.
- An empty cell includes a cell maker with a length of 2
- In addition, each row includes an end of row marker with a length of 2
Therefore, the row is empty if the string length is equal to the number of
cells in the row multiplied by 2 + 2.

You will find another macro version at:
http://word.mvps.org/FAQs/MacrosVBA/DeleteEmptyRows.htm

NOTE that both macro versions will fail if the table contains vertically
merged cells (requires some error handling).

For help on installing macros, see:
http://www.gmayor.com/installing_macro.htm

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Suzanne S. Barnhill" wrote:

If the table content is such that it can be sorted, then all blank rows will
sort to the top and can be easily deleted as a group. Barring that, you'll
need some sort of macro.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

"nhpaulao" wrote in message
...
How do i delete blank rows from tables in an automated manner? My table is
200 pages and contains random blank rows due to another automated process,
and I want to be able to search/replace blank rows or somehow delete them.


.

  #4  
Old January 13th, 2010, 12:05 PM posted to microsoft.public.word.tables
David
external usenet poster
 
Posts: 1,494
Default Automate removal of blank rows from table

May I add, I have a document that has nested tables that this macro missed. I
found that I have to iterate over oTable.Tables (which I created another sub
to do that I called reiteratively). Just thought you would like to know.

"Lene Fredborg" wrote:

If sorting is not an options, you can use the macro below:

Sub DeleteEmptyRows_AllTables()

Dim oTable As Table
Dim oRow As Row

For Each oTable In ActiveDocument.Tables
For Each oRow In oTable.Rows
'Check whether row is empty - delete if it is
If Len(oRow.Range.Text) = oRow.Cells.Count * 2 + 2 Then
oRow.Delete
End If
Next oRow
Next oTable

End Sub

How it works:
The macro iterates through all tables in the active document and finds (and
deletes) the empty rows by checking the total string length of each row.
- An empty cell includes a cell maker with a length of 2
- In addition, each row includes an end of row marker with a length of 2
Therefore, the row is empty if the string length is equal to the number of
cells in the row multiplied by 2 + 2.

You will find another macro version at:
http://word.mvps.org/FAQs/MacrosVBA/DeleteEmptyRows.htm

NOTE that both macro versions will fail if the table contains vertically
merged cells (requires some error handling).

For help on installing macros, see:
http://www.gmayor.com/installing_macro.htm

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Suzanne S. Barnhill" wrote:

If the table content is such that it can be sorted, then all blank rows will
sort to the top and can be easily deleted as a group. Barring that, you'll
need some sort of macro.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

"nhpaulao" wrote in message
...
How do i delete blank rows from tables in an automated manner? My table is
200 pages and contains random blank rows due to another automated process,
and I want to be able to search/replace blank rows or somehow delete them.


.

  #5  
Old January 13th, 2010, 12:08 PM posted to microsoft.public.word.tables
David
external usenet poster
 
Posts: 1,494
Default Automate removal of blank rows from table

May I add, I have a document that has nested tables that this macro missed. I
found that I have to iterate over oTable.Tables (which I created another sub
to do that I called reiteratively). Just thought you would like to know.


"Lene Fredborg" wrote:

If sorting is not an options, you can use the macro below:

Sub DeleteEmptyRows_AllTables()

Dim oTable As Table
Dim oRow As Row

For Each oTable In ActiveDocument.Tables
For Each oRow In oTable.Rows
'Check whether row is empty - delete if it is
If Len(oRow.Range.Text) = oRow.Cells.Count * 2 + 2 Then
oRow.Delete
End If
Next oRow
Next oTable

End Sub

How it works:
The macro iterates through all tables in the active document and finds (and
deletes) the empty rows by checking the total string length of each row.
- An empty cell includes a cell maker with a length of 2
- In addition, each row includes an end of row marker with a length of 2
Therefore, the row is empty if the string length is equal to the number of
cells in the row multiplied by 2 + 2.

You will find another macro version at:
http://word.mvps.org/FAQs/MacrosVBA/DeleteEmptyRows.htm

NOTE that both macro versions will fail if the table contains vertically
merged cells (requires some error handling).

For help on installing macros, see:
http://www.gmayor.com/installing_macro.htm

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Suzanne S. Barnhill" wrote:

If the table content is such that it can be sorted, then all blank rows will
sort to the top and can be easily deleted as a group. Barring that, you'll
need some sort of macro.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

"nhpaulao" wrote in message
...
How do i delete blank rows from tables in an automated manner? My table is
200 pages and contains random blank rows due to another automated process,
and I want to be able to search/replace blank rows or somehow delete them.


.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:11 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.