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  

Deleting extra rows in table



 
 
Thread Tools Display Modes
  #1  
Old February 8th, 2007, 08:37 PM posted to microsoft.public.word.tables
Gail
external usenet poster
 
Posts: 147
Default Deleting extra rows in table

I have a table that can be used either in printed form or online. When users
are done entering information online, there are blank rows at the end of the
table that need to be deleted. Can someone please give me a macro that just
deletes blank lines from the table? Thank you. I tried the macros in otehr
postings - and could not get them to work. HELP!
  #2  
Old February 9th, 2007, 08:09 AM posted to microsoft.public.word.tables
macropod
external usenet poster
 
Posts: 1,231
Default Deleting extra rows in table

Hi Gail,

The following code will delete all blank rows (except for those with vertically merged cells) in all tables in the 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 = "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

--
macropod
[MVP - Microsoft Word]


"Gail" wrote in message ...
| I have a table that can be used either in printed form or online. When users
| are done entering information online, there are blank rows at the end of the
| table that need to be deleted. Can someone please give me a macro that just
| deletes blank lines from the table? Thank you. I tried the macros in otehr
| postings - and could not get them to work. HELP!


  #3  
Old February 15th, 2007, 04:52 PM posted to microsoft.public.word.tables
Gail
external usenet poster
 
Posts: 147
Default Deleting extra rows in table

Thank you - it works perfectly!

"macropod" wrote:

Hi Gail,

The following code will delete all blank rows (except for those with vertically merged cells) in all tables in the 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 = "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

--
macropod
[MVP - Microsoft Word]


"Gail" wrote in message ...
| I have a table that can be used either in printed form or online. When users
| are done entering information online, there are blank rows at the end of the
| table that need to be deleted. Can someone please give me a macro that just
| deletes blank lines from the table? Thank you. I tried the macros in otehr
| postings - and could not get them to work. HELP!



 




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 01:58 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.