Discussion:
Search & Replace
(too old to reply)
Johann Swart
2010-01-03 07:09:01 UTC
Permalink
In Search & Replace (Find & Replace) where paragraph signs are involved, one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
Graham Mayor
2010-01-03 07:42:28 UTC
Permalink
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are involved, one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
Johann Swart
2010-01-04 11:22:01 UTC
Permalink
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or spaces between
the last character and the cell marker that I need to remove (quite laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a number of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are involved, one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
DeanH
2010-01-04 11:38:01 UTC
Permalink
Johann.
It was Macropod that suggested the ^10, and as you say this does not work
this [space]^10. I am still hoping for a solution.
What can work though if you are purely wanting to get rid of the superfluous
space before the cell end marker is to use the "old" trick of selecting the
text, align centre then align left (or left then centre). This will remove
all superfluous spaces, tabs, etc. at the end of paragraphs selected.
This works well, but obviously enusre that you select the text only not the
whole table, else the table itself will be aligned. I tend to select by
column, say columns 1 and 2 out of a 3-column table, do the trick, the n
select column 3 on its own, do the trick.
Not the best but does work well.
Lets see if anyone else can help with the Replace on [space] Cell End Marker.
Hope this helps
DeanH
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or spaces between
the last character and the cell marker that I need to remove (quite laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a number of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are involved, one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
Graham Mayor
2010-01-04 13:28:24 UTC
Permalink
The following macro will clear trailing spaces from all the cells in the
table containing the cursor

Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With

If you want to clear leading and trailing spaces change RTrim for Trim

Note that if you select the table and Click CTRL+E then CTRL+L all leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (¶) in table cell, but to the actual cell marker (€).
I have several documents that contain tables with a space or spaces between
the last character and the cell marker that I need to remove (quite laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a number of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
Graham Mayor
2010-01-04 13:32:50 UTC
Permalink
To process all the tables change that to

Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells in the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for Trim
Note that if you select the table and Click CTRL+E then CTRL+L all leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (¶) in table cell, but to the actual cell marker (€).
I have several documents that contain tables with a space or spaces between
the last character and the cell marker that I need to remove (quite laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a number of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
DeanH
2010-01-05 08:46:01 UTC
Permalink
Hello Graham.
Many thanks for these two macros.
Unfortunately both fail at:
Set oRng = .Cell(I, j).Range

Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells in the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for Trim
Note that if you select the table and Click CTRL+E then CTRL+L all leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or spaces between
the last character and the cell marker that I need to remove (quite laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a number of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
.
Graham Mayor
2010-01-05 09:22:48 UTC
Permalink
The thing that occurs is that you may have merged cells in your table. The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells in the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for Trim
Note that if you select the table and Click CTRL+E then CTRL+L all leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (¶) in table cell, but to the actual cell marker (€).
I have several documents that contain tables with a space or spaces between
the last character and the cell marker that I need to remove (quite laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a
number
of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
.
DeanH
2010-01-05 10:11:01 UTC
Permalink
Graham, yep that was it, two cells in the header row were merged in the test
table.
Many thanks
DeanH
Post by Graham Mayor
The thing that occurs is that you may have merged cells in your table. The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells in the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for Trim
Note that if you select the table and Click CTRL+E then CTRL+L all leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or spaces between
the last character and the cell marker that I need to remove (quite laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a
number
of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
.
.
Doug Robbins - Word MVP
2010-01-05 10:31:16 UTC
Permalink
Note that you can step through all of the cells of a table that contains
merged cells by using

Dim acell As Cell
For Each acell In ActiveDocument.Tables(1).Range.Cells
'Do something with each cell
Next acell
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by DeanH
Graham, yep that was it, two cells in the header row were merged in the test
table.
Many thanks
DeanH
Post by Graham Mayor
The thing that occurs is that you may have merged cells in your table. The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells in the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for Trim
Note that if you select the table and Click CTRL+E then CTRL+L all leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or spaces between
the last character and the cell marker that I need to remove (quite laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a
number
of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
.
.
Graham Mayor
2010-01-05 12:20:09 UTC
Permalink
Good thinking - that would equate to

Dim oRng As Range
Dim oTable As Table
Dim acell As Cell
For Each oTable In ActiveDocument.Tables
With oTable
For Each acell In oTable.Range.Cells
Set oRng = acell.Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next acell
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Doug Robbins - Word MVP
Note that you can step through all of the cells of a table that contains
merged cells by using
Dim acell As Cell
For Each acell In ActiveDocument.Tables(1).Range.Cells
'Do something with each cell
Next acell
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by DeanH
Graham, yep that was it, two cells in the header row were merged in the test
table.
Many thanks
DeanH
Post by Graham Mayor
The thing that occurs is that you may have merged cells in your table. The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells
in
the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for Trim
Note that if you select the table and Click CTRL+E then CTRL+L all leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (¶) in table cell, but to the actual cell marker (€).
I have several documents that contain tables with a space or
spaces
between
the last character and the cell marker that I need to remove
(quite
laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a
number
of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
.
.
David Turner
2010-03-18 19:01:01 UTC
Permalink
Post by Graham Mayor
Good thinking - that would equate to
Dim oRng As Range
Dim oTable As Table
Dim acell As Cell
For Each oTable In ActiveDocument.Tables
With oTable
For Each acell In oTable.Range.Cells
Set oRng = acell.Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next acell
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Might be best to first check whether there is actually a space before the
end of cell marker to avoid unnecessary trimming.

Sub RemSpaceBeforeCellMarker()

Dim oRng As Range
Dim oTable As Table
Dim acell As Cell
For Each oTable In ActiveDocument.Tables
With oTable
For Each acell In oTable.Range.Cells
Set oRng = acell.Range
oRng.End = oRng.End - 1
If Right(oRng.Text, 1) = " " Then
oRng.Text = RTrim(oRng.Text)
End If
Next acell
End With
Next oTable

End Sub
Graham Mayor
2010-03-19 06:37:55 UTC
Permalink
Post by David Turner
Might be best to first check whether there is actually a space before the
end of cell marker to avoid unnecessary trimming.
If there is no space nothing is trimmed, so the extra test would appear
superfluous?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Johann Swart
2010-01-05 12:30:01 UTC
Permalink
So then, it would appear as though there is no "one size fits all" solution.
Many thanks to all contributors!
Post by Doug Robbins - Word MVP
Note that you can step through all of the cells of a table that contains
merged cells by using
Dim acell As Cell
For Each acell In ActiveDocument.Tables(1).Range.Cells
'Do something with each cell
Next acell
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by DeanH
Graham, yep that was it, two cells in the header row were merged in the test
table.
Many thanks
DeanH
Post by Graham Mayor
The thing that occurs is that you may have merged cells in your table. The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells in the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for Trim
Note that if you select the table and Click CTRL+E then CTRL+L all leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to
paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or spaces
between
the last character and the cell marker that I need to remove (quite
laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a
number
of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the
document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in
tables?
.
.
.
Doug Robbins - Word MVP
2010-01-05 19:37:15 UTC
Permalink
I believe that the code posted by Graham will work for all of the "sizes"
mentioned. What other "sizes" were you thinking about.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by Johann Swart
So then, it would appear as though there is no "one size fits all" solution.
Many thanks to all contributors!
Post by Doug Robbins - Word MVP
Note that you can step through all of the cells of a table that contains
merged cells by using
Dim acell As Cell
For Each acell In ActiveDocument.Tables(1).Range.Cells
'Do something with each cell
Next acell
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by DeanH
Graham, yep that was it, two cells in the header row were merged in
the
test
table.
Many thanks
DeanH
Post by Graham Mayor
The thing that occurs is that you may have merged cells in your table. The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells
in
the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for Trim
Note that if you select the table and Click CTRL+E then CTRL+L
all
leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to
paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or spaces
between
the last character and the cell marker that I need to remove (quite
laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a
number
of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the
document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in
tables?
.
.
.
Johann Swart
2010-01-08 10:37:01 UTC
Permalink
Graham Mayor posted a macro that clears tables of leading and trailing spaces.
Before I could put it to the test, DeanH wrote that he experienced failure
of this macro, which was then attributed to merged cells.
Doug Robbins then posted a macro to find merged cells, and then to manually
do whatever is required.
Both macros are certainly valuable and will help me a great deal; many
thanks Graham.
As my tables are riddled with merged cells, it will still require a
significant degree of "manual labour" to take care of merged cells
separately; hence my "one size..." (read "one macro") comment.
Again, sincere thanks. It certainly beats inspecting thousands of cells one
by one.
Post by Doug Robbins - Word MVP
I believe that the code posted by Graham will work for all of the "sizes"
mentioned. What other "sizes" were you thinking about.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by Johann Swart
So then, it would appear as though there is no "one size fits all" solution.
Many thanks to all contributors!
Post by Doug Robbins - Word MVP
Note that you can step through all of the cells of a table that contains
merged cells by using
Dim acell As Cell
For Each acell In ActiveDocument.Tables(1).Range.Cells
'Do something with each cell
Next acell
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by DeanH
Graham, yep that was it, two cells in the header row were merged in
the
test
table.
Many thanks
DeanH
Post by Graham Mayor
The thing that occurs is that you may have merged cells in your table. The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells
in
the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for
Trim
Note that if you select the table and Click CTRL+E then CTRL+L
all
leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to
paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or spaces
between
the last character and the cell marker that I need to remove (quite
laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a
number
of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the
document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs
are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in
tables?
.
.
.
.
DeanH
2010-01-08 11:37:02 UTC
Permalink
Hi Johann. The revised macro with the "acell" works very well with merged
cells.
I have tested this with some very complex tables and no problems have been
noticed.
Graham - many thanks.
DeanH
Post by Johann Swart
Graham Mayor posted a macro that clears tables of leading and trailing spaces.
Before I could put it to the test, DeanH wrote that he experienced failure
of this macro, which was then attributed to merged cells.
Doug Robbins then posted a macro to find merged cells, and then to manually
do whatever is required.
Both macros are certainly valuable and will help me a great deal; many
thanks Graham.
As my tables are riddled with merged cells, it will still require a
significant degree of "manual labour" to take care of merged cells
separately; hence my "one size..." (read "one macro") comment.
Again, sincere thanks. It certainly beats inspecting thousands of cells one
by one.
Post by Doug Robbins - Word MVP
I believe that the code posted by Graham will work for all of the "sizes"
mentioned. What other "sizes" were you thinking about.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by Johann Swart
So then, it would appear as though there is no "one size fits all" solution.
Many thanks to all contributors!
Post by Doug Robbins - Word MVP
Note that you can step through all of the cells of a table that contains
merged cells by using
Dim acell As Cell
For Each acell In ActiveDocument.Tables(1).Range.Cells
'Do something with each cell
Next acell
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by DeanH
Graham, yep that was it, two cells in the header row were merged in
the
test
table.
Many thanks
DeanH
Post by Graham Mayor
The thing that occurs is that you may have merged cells in your table. The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells
in
the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for
Trim
Note that if you select the table and Click CTRL+E then CTRL+L
all
leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to
paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or
spaces
between
the last character and the cell marker that I need to remove
(quite
laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a
number
of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the
document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs
are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in
tables?
.
.
.
.
Johann Swart
2010-01-11 09:01:01 UTC
Permalink
Suddenly the lights went on! Thanks Dean.
Post by DeanH
Hi Johann. The revised macro with the "acell" works very well with merged
cells.
I have tested this with some very complex tables and no problems have been
noticed.
Graham - many thanks.
DeanH
Post by Johann Swart
Graham Mayor posted a macro that clears tables of leading and trailing spaces.
Before I could put it to the test, DeanH wrote that he experienced failure
of this macro, which was then attributed to merged cells.
Doug Robbins then posted a macro to find merged cells, and then to manually
do whatever is required.
Both macros are certainly valuable and will help me a great deal; many
thanks Graham.
As my tables are riddled with merged cells, it will still require a
significant degree of "manual labour" to take care of merged cells
separately; hence my "one size..." (read "one macro") comment.
Again, sincere thanks. It certainly beats inspecting thousands of cells one
by one.
Post by Doug Robbins - Word MVP
I believe that the code posted by Graham will work for all of the "sizes"
mentioned. What other "sizes" were you thinking about.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by Johann Swart
So then, it would appear as though there is no "one size fits all" solution.
Many thanks to all contributors!
Post by Doug Robbins - Word MVP
Note that you can step through all of the cells of a table that contains
merged cells by using
Dim acell As Cell
For Each acell In ActiveDocument.Tables(1).Range.Cells
'Do something with each cell
Next acell
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by DeanH
Graham, yep that was it, two cells in the header row were merged in
the
test
table.
Many thanks
DeanH
Post by Graham Mayor
The thing that occurs is that you may have merged cells in your table.
The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells
in
the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for
Trim
Note that if you select the table and Click CTRL+E then CTRL+L
all
leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to
paragraph
breaks (¶) in table cell, but to the actual cell marker (¤).
I have several documents that contain tables with a space or
spaces
between
the last character and the cell marker that I need to remove
(quite
laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a
number
of
permutations, and frankly, some weird things happen.
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the
document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs
are
involved,
one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in
tables?
.
.
.
.
Peter Cooper
2011-01-19 14:44:29 UTC
Permalink
Thanks for the question and comments, as I have to do similar things. As I have sometimes done before, I have decided to convert the table to text, with tabs. Then Replace, and convert back to a table. The Replace behaviour seems more understandable and controllable then.
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are involved, one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
Post by Graham Mayor
Paragraph breaks are paragraph breaks wherever they are in the document.
What *exactly* are you trying to do?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by macropod
Hi Johann,
You can also use ^10 with wildcards, and this works with the table cell markers as well.
--
Cheers
macropod
[Microsoft MVP - Word]
Post by DeanH
Hello Macropod (Happy New Year)
This ^10 does not work in the Find/Replace with wildcards checked.
I have 2003 on XP, should this work?
I have for many years wanted to find the code for the cell markers with no
joy, so any calification would be much appreciated.
Many thanks
DeanH
Post by DeanH
Sorry, to clarify.
^10 does work but not on its own or with a space before.
As previously described in a previous posting, if you search for Wa^10 -
this will be found, But [space]^10 will not be found, any space will be found.
I have noticed Doug's macro and may have a play with that, any other ideas?
Thanks
DeanH
Post by macropod
Hi Dean,
Works fine in Word 2000. It seems to be just another thing that took a backward step with later versions ...
--
Cheers
macropod
[Microsoft MVP - Word]
Post by Johann Swart
Hi Graham,
Apologies; I expressed myself incorrectly. I am not referring to paragraph
breaks (??) in table cell, but to the actual cell marker (??).
I have several documents that contain tables with a space or spaces between
the last character and the cell marker that I need to remove (quite laborious
in a 100-page document riddled with tables).
The ^10 suggested by DeanH does not do it either. I have tried a number of
permutations, and frankly, some weird things happen.
Post by DeanH
Johann.
It was Macropod that suggested the ^10, and as you say this does not work
this [space]^10. I am still hoping for a solution.
What can work though if you are purely wanting to get rid of the superfluous
space before the cell end marker is to use the "old" trick of selecting the
text, align centre then align left (or left then centre). This will remove
all superfluous spaces, tabs, etc. at the end of paragraphs selected.
This works well, but obviously enusre that you select the text only not the
whole table, else the table itself will be aligned. I tend to select by
column, say columns 1 and 2 out of a 3-column table, do the trick, the n
select column 3 on its own, do the trick.
Not the best but does work well.
Lets see if anyone else can help with the Replace on [space] Cell End Marker.
Hope this helps
DeanH
Post by Graham Mayor
The following macro will clear trailing spaces from all the cells in the
table containing the cursor
Dim oRng As Range
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
If you want to clear leading and trailing spaces change RTrim for Trim
Note that if you select the table and Click CTRL+E then CTRL+L all leading
and trailing white space will be cleared from the table.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
To process all the tables change that to
Dim oRng As Range
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set oRng = .Cell(i, j).Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next j
Next i
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Pamelia Caswell via OfficeKB.com
I just tried searching for " face^10", "face ^10", and " ^10" in W2009. All
work with wild cards enabled. It selects only up to the end of cell
marker???probably because the marker cannot be manipulated. It also replaces
only up to the end of cell marker.
Thanks, Paul.
Pam
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-tables/201001/1
Post by Pamelia Caswell via OfficeKB.com
It also works with " {1,}^10. I too have had to delete trailing spaces from
dozens of tables and hundreds of cells???by hand. So this could be a big help.
Pam
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-tables/201001/1
Post by DeanH
Hi Pamela.
Unfortuantely, this still does not work, it finds any space in the table,
not just a space next to the Cell End Marker, which is what is required. Oh
well never mind.
Thanks anyway.
DeanH
Post by DeanH
Hello Graham.
Many thanks for these two macros.
Set oRng = .Cell(I, j).Range
Any ideas?
DeanH
Post by Graham Mayor
The thing that occurs is that you may have merged cells in your table. The
macros will not work with merged or split cells.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by DeanH
Graham, yep that was it, two cells in the header row were merged in the test
table.
Many thanks
DeanH
Post by Doug Robbins - Word MVP
Note that you can step through all of the cells of a table that contains
merged cells by using
Dim acell As Cell
For Each acell In ActiveDocument.Tables(1).Range.Cells
'Do something with each cell
Next acell
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by Graham Mayor
Good thinking - that would equate to
Dim oRng As Range
Dim oTable As Table
Dim acell As Cell
For Each oTable In ActiveDocument.Tables
With oTable
For Each acell In oTable.Range.Cells
Set oRng = acell.Range
oRng.End = oRng.End - 1
oRng.Text = RTrim(oRng.Text)
Next acell
End With
Next oTable
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Johann Swart
So then, it would appear as though there is no "one size fits all" solution.
Many thanks to all contributors!
Post by Doug Robbins - Word MVP
I believe that the code posted by Graham will work for all of the "sizes"
mentioned. What other "sizes" were you thinking about.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Post by macropod
W2009?
--
Cheers
macropod
[Microsoft MVP - Word]
2007. Fingers slipped. And I am very disappointed that ^10 does not work in
W2007.
Pam
--
Message posted via http://www.officekb.com
Post by Johann Swart
Graham Mayor posted a macro that clears tables of leading and trailing spaces.
Before I could put it to the test, DeanH wrote that he experienced failure
of this macro, which was then attributed to merged cells.
Doug Robbins then posted a macro to find merged cells, and then to manually
do whatever is required.
Both macros are certainly valuable and will help me a great deal; many
thanks Graham.
As my tables are riddled with merged cells, it will still require a
significant degree of "manual labour" to take care of merged cells
separately; hence my "one size..." (read "one macro") comment.
Again, sincere thanks. It certainly beats inspecting thousands of cells one
by one.
Post by DeanH
Hi Johann. The revised macro with the "acell" works very well with merged
cells.
I have tested this with some very complex tables and no problems have been
noticed.
Graham - many thanks.
DeanH
Post by Johann Swart
Suddenly the lights went on! Thanks Dean.
Post by David Turner
Might be best to first check whether there is actually a space before the
end of cell marker to avoid unnecessary trimming.
Sub RemSpaceBeforeCellMarker()
Dim oRng As Range
Dim oTable As Table
Dim acell As Cell
For Each oTable In ActiveDocument.Tables
With oTable
For Each acell In oTable.Range.Cells
Set oRng = acell.Range
oRng.End = oRng.End - 1
If Right(oRng.Text, 1) = " " Then
oRng.Text = RTrim(oRng.Text)
End If
Next acell
End With
Next oTable
End Sub
Post by Graham Mayor
If there is no space nothing is trimmed, so the extra test would appear
superfluous?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Submitted via EggHeadCafe
Excel Generate High Quality RoadMaps
http://www.eggheadcafe.com/tutorials/aspnet/3310004f-e1ae-45a7-9bea-7b2b970d1230/excel-generate-high-quality-roadmaps.aspx
macropod
2010-01-03 08:57:50 UTC
Permalink
Hi Johann,

You can also use ^10 with wildcards, and this works with the table cell markers as well.
--
Cheers
macropod
[Microsoft MVP - Word]
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are involved, one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
DeanH
2010-01-04 09:43:01 UTC
Permalink
Hello Macropod (Happy New Year)
This ^10 does not work in the Find/Replace with wildcards checked.
I have 2003 on XP, should this work?
I have for many years wanted to find the code for the cell markers with no
joy, so any calification would be much appreciated.
Many thanks
DeanH
Post by macropod
Hi Johann,
You can also use ^10 with wildcards, and this works with the table cell markers as well.
--
Cheers
macropod
[Microsoft MVP - Word]
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are involved, one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
DeanH
2010-01-04 09:51:01 UTC
Permalink
Sorry, to clarify.
^10 does work but not on its own or with a space before.
As previously described in a previous posting, if you search for Wa^10 -
this will be found, But [space]^10 will not be found, any space will be found.
I have noticed Doug's macro and may have a play with that, any other ideas?
Thanks
DeanH
Post by DeanH
Hello Macropod (Happy New Year)
This ^10 does not work in the Find/Replace with wildcards checked.
I have 2003 on XP, should this work?
I have for many years wanted to find the code for the cell markers with no
joy, so any calification would be much appreciated.
Many thanks
DeanH
Post by macropod
Hi Johann,
You can also use ^10 with wildcards, and this works with the table cell markers as well.
--
Cheers
macropod
[Microsoft MVP - Word]
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are involved, one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
macropod
2010-01-04 10:05:03 UTC
Permalink
Hi Dean,

Works fine in Word 2000. It seems to be just another thing that took a backward step with later versions ...
--
Cheers
macropod
[Microsoft MVP - Word]
Post by DeanH
Sorry, to clarify.
^10 does work but not on its own or with a space before.
As previously described in a previous posting, if you search for Wa^10 -
this will be found, But [space]^10 will not be found, any space will be found.
I have noticed Doug's macro and may have a play with that, any other ideas?
Thanks
DeanH
Post by DeanH
Hello Macropod (Happy New Year)
This ^10 does not work in the Find/Replace with wildcards checked.
I have 2003 on XP, should this work?
I have for many years wanted to find the code for the cell markers with no
joy, so any calification would be much appreciated.
Many thanks
DeanH
Post by macropod
Hi Johann,
You can also use ^10 with wildcards, and this works with the table cell markers as well.
--
Cheers
macropod
[Microsoft MVP - Word]
Post by Johann Swart
In Search & Replace (Find & Replace) where paragraph signs are involved, one
would use ^p in normal text or ^13 when using wild cards.
What are the equivalent codes when using Search & Replace in tables?
.
Pamelia Caswell via OfficeKB.com
2010-01-04 16:57:09 UTC
Permalink
I just tried searching for " face^10", "face ^10", and " ^10" in W2009. All
work with wild cards enabled. It selects only up to the end of cell
marker—probably because the marker cannot be manipulated. It also replaces
only up to the end of cell marker.

Thanks, Paul.

Pam
Post by macropod
Hi Dean,
Works fine in Word 2000. It seems to be just another thing that took a backward step with later versions ...
Post by DeanH
Sorry, to clarify.
^10 does work but not on its own or with a space before.
[quoted text clipped - 20 lines]
Post by DeanH
Post by Johann Swart
What are the equivalent codes when using Search & Replace in tables?
.
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-tables/201001/1
Pamelia Caswell via OfficeKB.com
2010-01-04 20:21:39 UTC
Permalink
It also works with " {1,}^10. I too have had to delete trailing spaces from
dozens of tables and hundreds of cells—by hand. So this could be a big help.


Pam
Post by Pamelia Caswell via OfficeKB.com
I just tried searching for " face^10", "face ^10", and " ^10" in W2009. All
work with wild cards enabled. It selects only up to the end of cell
marker—probably because the marker cannot be manipulated. It also replaces
only up to the end of cell marker.
Thanks, Paul.
Pam
Post by macropod
Hi Dean,
[quoted text clipped - 5 lines]
Post by macropod
Post by Johann Swart
What are the equivalent codes when using Search & Replace in tables?
.
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-tables/201001/1
DeanH
2010-01-05 08:34:01 UTC
Permalink
Hi Pamela.
Unfortuantely, this still does not work, it finds any space in the table,
not just a space next to the Cell End Marker, which is what is required. Oh
well never mind.
Thanks anyway.

DeanH
Post by Pamelia Caswell via OfficeKB.com
It also works with " {1,}^10. I too have had to delete trailing spaces from
dozens of tables and hundreds of cells—by hand. So this could be a big help.
Pam
Post by Pamelia Caswell via OfficeKB.com
I just tried searching for " face^10", "face ^10", and " ^10" in W2009. All
work with wild cards enabled. It selects only up to the end of cell
marker—probably because the marker cannot be manipulated. It also replaces
only up to the end of cell marker.
Thanks, Paul.
Pam
Post by macropod
Hi Dean,
[quoted text clipped - 5 lines]
Post by macropod
Post by Johann Swart
What are the equivalent codes when using Search & Replace in tables?
.
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-tables/201001/1
.
macropod
2010-01-05 21:00:23 UTC
Permalink
W2009?
--
Cheers
macropod
[Microsoft MVP - Word]
Post by Pamelia Caswell via OfficeKB.com
I just tried searching for " face^10", "face ^10", and " ^10" in W2009. All
work with wild cards enabled. It selects only up to the end of cell
marker—probably because the marker cannot be manipulated. It also replaces
only up to the end of cell marker.
Thanks, Paul.
Pam
Post by macropod
Hi Dean,
Works fine in Word 2000. It seems to be just another thing that took a backward step with later versions ...
Post by DeanH
Sorry, to clarify.
^10 does work but not on its own or with a space before.
[quoted text clipped - 20 lines]
Post by DeanH
Post by Johann Swart
What are the equivalent codes when using Search & Replace in tables?
.
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-tables/201001/1
Pamelia Caswell via OfficeKB.com
2010-01-06 00:51:10 UTC
Permalink
2007. Fingers slipped. And I'm very disappointed that ^10 doesn't work in
W2007.

Pam
Post by macropod
W2009?
Post by Pamelia Caswell via OfficeKB.com
I just tried searching for " face^10", "face ^10", and " ^10" in W2009. All
work with wild cards enabled. It selects only up to the end of cell
[quoted text clipped - 14 lines]
Post by Pamelia Caswell via OfficeKB.com
Post by Johann Swart
What are the equivalent codes when using Search & Replace in tables?
.
--
Message posted via http://www.officekb.com
Loading...