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  

Quick way to delete empty rows?



 
 
Thread Tools Display Modes
  #1  
Old September 6th, 2007, 07:22 PM posted to microsoft.public.word.tables
Beth Brooks
external usenet poster
 
Posts: 2
Default Quick way to delete empty rows?

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth
  #2  
Old September 6th, 2007, 11:02 PM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Quick way to delete empty rows?

You can use a macro to delete all the empty rows. The macro below should do
the job.

---------------
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
Exit Sub

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
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Beth Brooks" wrote:

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth

  #3  
Old November 9th, 2007, 11:18 PM posted to microsoft.public.word.tables
Tanya
external usenet poster
 
Posts: 169
Default Quick way to delete empty rows?

I tested this macro in my merge document. I am having a problem with it
deleting rows in all merged letters based on the first letter instead of
deleting based on the individual letter. Is there a way to avoid this?

"Lene Fredborg" wrote:

You can use a macro to delete all the empty rows. The macro below should do
the job.

---------------
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
Exit Sub

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
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Beth Brooks" wrote:

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth

  #4  
Old November 10th, 2007, 11:13 AM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Quick way to delete empty rows?

Could you provide more details about the problem. What happens? Do you see an
error message - and in that case, what doet it tell?

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


"Tanya" wrote:

I tested this macro in my merge document. I am having a problem with it
deleting rows in all merged letters based on the first letter instead of
deleting based on the individual letter. Is there a way to avoid this?

"Lene Fredborg" wrote:

You can use a macro to delete all the empty rows. The macro below should do
the job.

---------------
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
Exit Sub

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
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Beth Brooks" wrote:

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth

  #5  
Old November 12th, 2007, 05:37 PM posted to microsoft.public.word.tables
Tanya
external usenet poster
 
Posts: 169
Default Quick way to delete empty rows?

I am not getting an error message. I want the macro to run on all tables
within a merged document. The macro needs to loop through each merge record
base on each unique mergefield.

"Lene Fredborg" wrote:

Could you provide more details about the problem. What happens? Do you see an
error message - and in that case, what doet it tell?

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


"Tanya" wrote:

I tested this macro in my merge document. I am having a problem with it
deleting rows in all merged letters based on the first letter instead of
deleting based on the individual letter. Is there a way to avoid this?

"Lene Fredborg" wrote:

You can use a macro to delete all the empty rows. The macro below should do
the job.

---------------
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
Exit Sub

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
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Beth Brooks" wrote:

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth

  #6  
Old November 12th, 2007, 06:10 PM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Quick way to delete empty rows?

I am not sure I understand exactly what you want to do. The macro does what
is described in my first post: deletes empty rows in _all_ tables in the
active document. Do you want the macro to delete empty rows in only one
_section_ of the document (each section corresponding to a letter)?. If that
is the case, try to replace the code line:

For Each oTable In ActiveDocument.Tables

with the following line:

For Each oTable In Selection.Sections(1).Range.Tables

Then the macro will only delete empty rows from the tables in the section in
which the insertion point is found (or in case you have selected text, in the
section where the selection starts).

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


"Tanya" wrote:

I am not getting an error message. I want the macro to run on all tables
within a merged document. The macro needs to loop through each merge record
base on each unique mergefield.

"Lene Fredborg" wrote:

Could you provide more details about the problem. What happens? Do you see an
error message - and in that case, what doet it tell?

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


"Tanya" wrote:

I tested this macro in my merge document. I am having a problem with it
deleting rows in all merged letters based on the first letter instead of
deleting based on the individual letter. Is there a way to avoid this?

"Lene Fredborg" wrote:

You can use a macro to delete all the empty rows. The macro below should do
the job.

---------------
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
Exit Sub

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
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Beth Brooks" wrote:

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth

  #7  
Old January 4th, 2008, 04:27 PM posted to microsoft.public.word.tables
Lightjag
external usenet poster
 
Posts: 23
Default Quick way to delete empty rows?

I have the same problem, I am using the following macro:

Sub DeleteEmptyRows()
'
' DeleteEmptyRows Macro
'
'
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
Exit Sub

End Sub

The issue is that once a mail merge is done and you have say 100 pages of
tables (each table seperated by a ":::::::::::section break (next
page)::::::::::"), and you run the macro above, ONLY the blank rows in the
FIRST Table/page are deleted. My tables have 6 columns and 21 rows. FYI -
if I move to the next table/page

"Lene Fredborg" wrote:

I am not sure I understand exactly what you want to do. The macro does what
is described in my first post: deletes empty rows in _all_ tables in the
active document. Do you want the macro to delete empty rows in only one
_section_ of the document (each section corresponding to a letter)?. If that
is the case, try to replace the code line:

For Each oTable In ActiveDocument.Tables

with the following line:

For Each oTable In Selection.Sections(1).Range.Tables

Then the macro will only delete empty rows from the tables in the section in
which the insertion point is found (or in case you have selected text, in the
section where the selection starts).

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


"Tanya" wrote:

I am not getting an error message. I want the macro to run on all tables
within a merged document. The macro needs to loop through each merge record
base on each unique mergefield.

"Lene Fredborg" wrote:

Could you provide more details about the problem. What happens? Do you see an
error message - and in that case, what doet it tell?

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


"Tanya" wrote:

I tested this macro in my merge document. I am having a problem with it
deleting rows in all merged letters based on the first letter instead of
deleting based on the individual letter. Is there a way to avoid this?

"Lene Fredborg" wrote:

You can use a macro to delete all the empty rows. The macro below should do
the job.

---------------
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
Exit Sub

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
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Beth Brooks" wrote:

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth

  #8  
Old January 4th, 2008, 05:36 PM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Quick way to delete empty rows?

I just made a test with mail merge and the macro deleted every empty row in
every table throughout the document. I don't know what causes your problem.

Are the rows really empty – have you turned on non-printing characters
(Ctrl+Shift+8) to check that there are no spaces, tabs or other non-printing
characters?

Have you tried stepping through the macro using F8 in the VBE editor while
you watch what happens in your document?

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


"Lightjag" wrote:

I have the same problem, I am using the following macro:

Sub DeleteEmptyRows()
'
' DeleteEmptyRows Macro
'
'
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
Exit Sub

End Sub

The issue is that once a mail merge is done and you have say 100 pages of
tables (each table seperated by a ":::::::::::section break (next
page)::::::::::"), and you run the macro above, ONLY the blank rows in the
FIRST Table/page are deleted. My tables have 6 columns and 21 rows. FYI -
if I move to the next table/page

"Lene Fredborg" wrote:

I am not sure I understand exactly what you want to do. The macro does what
is described in my first post: deletes empty rows in _all_ tables in the
active document. Do you want the macro to delete empty rows in only one
_section_ of the document (each section corresponding to a letter)?. If that
is the case, try to replace the code line:

For Each oTable In ActiveDocument.Tables

with the following line:

For Each oTable In Selection.Sections(1).Range.Tables

Then the macro will only delete empty rows from the tables in the section in
which the insertion point is found (or in case you have selected text, in the
section where the selection starts).

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


"Tanya" wrote:

I am not getting an error message. I want the macro to run on all tables
within a merged document. The macro needs to loop through each merge record
base on each unique mergefield.

"Lene Fredborg" wrote:

Could you provide more details about the problem. What happens? Do you see an
error message - and in that case, what doet it tell?

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


"Tanya" wrote:

I tested this macro in my merge document. I am having a problem with it
deleting rows in all merged letters based on the first letter instead of
deleting based on the individual letter. Is there a way to avoid this?

"Lene Fredborg" wrote:

You can use a macro to delete all the empty rows. The macro below should do
the job.

---------------
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
Exit Sub

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
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Beth Brooks" wrote:

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth

  #9  
Old January 4th, 2008, 06:54 PM posted to microsoft.public.word.tables
Lightjag
external usenet poster
 
Posts: 23
Default Quick way to delete empty rows?

Thanks it works now. I had to remove the "tabs" that where infront of the
fields (pulling from excel).

"Lene Fredborg" wrote:

I just made a test with mail merge and the macro deleted every empty row in
every table throughout the document. I don't know what causes your problem.

Are the rows really empty – have you turned on non-printing characters
(Ctrl+Shift+8) to check that there are no spaces, tabs or other non-printing
characters?

Have you tried stepping through the macro using F8 in the VBE editor while
you watch what happens in your document?

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


"Lightjag" wrote:

I have the same problem, I am using the following macro:

Sub DeleteEmptyRows()
'
' DeleteEmptyRows Macro
'
'
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
Exit Sub

End Sub

The issue is that once a mail merge is done and you have say 100 pages of
tables (each table seperated by a ":::::::::::section break (next
page)::::::::::"), and you run the macro above, ONLY the blank rows in the
FIRST Table/page are deleted. My tables have 6 columns and 21 rows. FYI -
if I move to the next table/page

"Lene Fredborg" wrote:

I am not sure I understand exactly what you want to do. The macro does what
is described in my first post: deletes empty rows in _all_ tables in the
active document. Do you want the macro to delete empty rows in only one
_section_ of the document (each section corresponding to a letter)?. If that
is the case, try to replace the code line:

For Each oTable In ActiveDocument.Tables

with the following line:

For Each oTable In Selection.Sections(1).Range.Tables

Then the macro will only delete empty rows from the tables in the section in
which the insertion point is found (or in case you have selected text, in the
section where the selection starts).

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


"Tanya" wrote:

I am not getting an error message. I want the macro to run on all tables
within a merged document. The macro needs to loop through each merge record
base on each unique mergefield.

"Lene Fredborg" wrote:

Could you provide more details about the problem. What happens? Do you see an
error message - and in that case, what doet it tell?

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


"Tanya" wrote:

I tested this macro in my merge document. I am having a problem with it
deleting rows in all merged letters based on the first letter instead of
deleting based on the individual letter. Is there a way to avoid this?

"Lene Fredborg" wrote:

You can use a macro to delete all the empty rows. The macro below should do
the job.

---------------
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
Exit Sub

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
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Beth Brooks" wrote:

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth

  #10  
Old January 4th, 2008, 07:45 PM posted to microsoft.public.word.tables
Lightjag
external usenet poster
 
Posts: 23
Default Quick way to delete empty rows?

I would like to modify the macro below to delete a row based on a value in
one of the columns. For example, one of the columns is Port Value (with
field names p1, p2,.....p10). If any of the P {fields} return 0 (or bank, or
if P 1 would work) then delete row. What change would be require to the
macro? Thanks

"Lightjag" wrote:

Thanks it works now. I had to remove the "tabs" that where infront of the
fields (pulling from excel).

"Lene Fredborg" wrote:

I just made a test with mail merge and the macro deleted every empty row in
every table throughout the document. I don't know what causes your problem.

Are the rows really empty – have you turned on non-printing characters
(Ctrl+Shift+8) to check that there are no spaces, tabs or other non-printing
characters?

Have you tried stepping through the macro using F8 in the VBE editor while
you watch what happens in your document?

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


"Lightjag" wrote:

I have the same problem, I am using the following macro:

Sub DeleteEmptyRows()
'
' DeleteEmptyRows Macro
'
'
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
Exit Sub

End Sub

The issue is that once a mail merge is done and you have say 100 pages of
tables (each table seperated by a ":::::::::::section break (next
page)::::::::::"), and you run the macro above, ONLY the blank rows in the
FIRST Table/page are deleted. My tables have 6 columns and 21 rows. FYI -
if I move to the next table/page

"Lene Fredborg" wrote:

I am not sure I understand exactly what you want to do. The macro does what
is described in my first post: deletes empty rows in _all_ tables in the
active document. Do you want the macro to delete empty rows in only one
_section_ of the document (each section corresponding to a letter)?. If that
is the case, try to replace the code line:

For Each oTable In ActiveDocument.Tables

with the following line:

For Each oTable In Selection.Sections(1).Range.Tables

Then the macro will only delete empty rows from the tables in the section in
which the insertion point is found (or in case you have selected text, in the
section where the selection starts).

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


"Tanya" wrote:

I am not getting an error message. I want the macro to run on all tables
within a merged document. The macro needs to loop through each merge record
base on each unique mergefield.

"Lene Fredborg" wrote:

Could you provide more details about the problem. What happens? Do you see an
error message - and in that case, what doet it tell?

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


"Tanya" wrote:

I tested this macro in my merge document. I am having a problem with it
deleting rows in all merged letters based on the first letter instead of
deleting based on the individual letter. Is there a way to avoid this?

"Lene Fredborg" wrote:

You can use a macro to delete all the empty rows. The macro below should do
the job.

---------------
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
Exit Sub

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
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Beth Brooks" wrote:

Hi!

I have provided with 150 tables to use in a document. Most of the tables
have empty rows (to divide data visually). Due to space considerations, I'd
like to get rid of all the blank rows. Is there a way to find and delete only
the empty rows in a table?

MS Word version is 2003. Operating system is Windows XP Professional Version
2002 Service Pack 2.

Thanks!

Beth

 




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 11:52 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.