From: Janine on
Below does not purge trailing space in a table:-

Fred Smith trailing space (no merge cells and anywhere in table rows)

What vba do tables require to clean up properly please?

Many thanks.

Sub Purge_Trailing_Space()
Dim s As String
With ActiveDocument
If Len(.Range) = 1 Then Exit Sub
s = .Characters.Last.Previous
While s = " " Or s = Chr(13) Or s = Chr(11)
.Characters.Last.Previous = ""
s = .Characters.Last.Previous
Wend
End With
End Sub


From: macropod on
Hi Janine,

That code does not relate to tables per se, but to a document generally. In part, the code attempts to delete the penultimate
character if it's a space or a paragraph break. However, there must always be at least one paragraph (empty or otherwise) following
the last table in a document.

What, exactly, are you trying to achieve?

--
Cheers
macropod
[Microsoft MVP - Word]


"Janine" <janine(a)ribbonspace.com> wrote in message news:DB476098-476B-43F0-85E9-EB065E1087EC(a)microsoft.com...
> Below does not purge trailing space in a table:-
>
> Fred Smith trailing space (no merge cells and anywhere in table rows)
>
> What vba do tables require to clean up properly please?
>
> Many thanks.
>
> Sub Purge_Trailing_Space()
> Dim s As String
> With ActiveDocument
> If Len(.Range) = 1 Then Exit Sub
> s = .Characters.Last.Previous
> While s = " " Or s = Chr(13) Or s = Chr(11)
> .Characters.Last.Previous = ""
> s = .Characters.Last.Previous
> Wend
> End With
> End Sub
>
>

From: Janine on
Hi Macropod - yes I figured that our (duh!).

I have a trailing autocorrect space in 3rd column but it could be any column
and the paragraph mark is non existent as I use styles and no carriage
returns (hardly ever).

Any way to search a trailing space with nothing following it?

"macropod" <macropod(a)invalid.invalid> wrote in message
news:#5R1xNZxKHA.4492(a)TK2MSFTNGP05.phx.gbl...
> Hi Janine,
>
> That code does not relate to tables per se, but to a document generally.
> In part, the code attempts to delete the penultimate character if it's a
> space or a paragraph break. However, there must always be at least one
> paragraph (empty or otherwise) following the last table in a document.
>
> What, exactly, are you trying to achieve?
>
> --
> Cheers
> macropod
> [Microsoft MVP - Word]
>
>
> "Janine" <janine(a)ribbonspace.com> wrote in message
> news:DB476098-476B-43F0-85E9-EB065E1087EC(a)microsoft.com...
>> Below does not purge trailing space in a table:-
>>
>> Fred Smith trailing space (no merge cells and anywhere in table rows)
>>
>> What vba do tables require to clean up properly please?
>>
>> Many thanks.
>>
>> Sub Purge_Trailing_Space()
>> Dim s As String
>> With ActiveDocument
>> If Len(.Range) = 1 Then Exit Sub
>> s = .Characters.Last.Previous
>> While s = " " Or s = Chr(13) Or s = Chr(11)
>> .Characters.Last.Previous = ""
>> s = .Characters.Last.Previous
>> Wend
>> End With
>> End Sub
>>
>>
>
From: Graham Mayor on
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

will clear trailing spaces from all the cells in all the tables in your
document.
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
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



"Janine" <janine(a)ribbonspace.com> wrote in message
news:57B3B1FA-967A-4EA1-8048-7EB8DA2B2283(a)microsoft.com...
> Hi Macropod - yes I figured that our (duh!).
>
> I have a trailing autocorrect space in 3rd column but it could be any
> column and the paragraph mark is non existent as I use styles and no
> carriage returns (hardly ever).
>
> Any way to search a trailing space with nothing following it?
>
> "macropod" <macropod(a)invalid.invalid> wrote in message
> news:#5R1xNZxKHA.4492(a)TK2MSFTNGP05.phx.gbl...
>> Hi Janine,
>>
>> That code does not relate to tables per se, but to a document generally.
>> In part, the code attempts to delete the penultimate character if it's a
>> space or a paragraph break. However, there must always be at least one
>> paragraph (empty or otherwise) following the last table in a document.
>>
>> What, exactly, are you trying to achieve?
>>
>> --
>> Cheers
>> macropod
>> [Microsoft MVP - Word]
>>
>>
>> "Janine" <janine(a)ribbonspace.com> wrote in message
>> news:DB476098-476B-43F0-85E9-EB065E1087EC(a)microsoft.com...
>>> Below does not purge trailing space in a table:-
>>>
>>> Fred Smith trailing space (no merge cells and anywhere in table rows)
>>>
>>> What vba do tables require to clean up properly please?
>>>
>>> Many thanks.
>>>
>>> Sub Purge_Trailing_Space()
>>> Dim s As String
>>> With ActiveDocument
>>> If Len(.Range) = 1 Then Exit Sub
>>> s = .Characters.Last.Previous
>>> While s = " " Or s = Chr(13) Or s = Chr(11)
>>> .Characters.Last.Previous = ""
>>> s = .Characters.Last.Previous
>>> Wend
>>> End With
>>> End Sub
>>>
>>>
>>


From: Janine on
Thank you Graham Trim did the trick.

"Graham Mayor" <gmayor(a)REMOVETHISmvps.org> wrote in message
news:#tRHhBaxKHA.4240(a)TK2MSFTNGP06.phx.gbl...
> 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
>
> will clear trailing spaces from all the cells in all the tables in your
> document.
> 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
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
>
> "Janine" <janine(a)ribbonspace.com> wrote in message
> news:57B3B1FA-967A-4EA1-8048-7EB8DA2B2283(a)microsoft.com...
>> Hi Macropod - yes I figured that our (duh!).
>>
>> I have a trailing autocorrect space in 3rd column but it could be any
>> column and the paragraph mark is non existent as I use styles and no
>> carriage returns (hardly ever).
>>
>> Any way to search a trailing space with nothing following it?
>>
>> "macropod" <macropod(a)invalid.invalid> wrote in message
>> news:#5R1xNZxKHA.4492(a)TK2MSFTNGP05.phx.gbl...
>>> Hi Janine,
>>>
>>> That code does not relate to tables per se, but to a document generally.
>>> In part, the code attempts to delete the penultimate character if it's a
>>> space or a paragraph break. However, there must always be at least one
>>> paragraph (empty or otherwise) following the last table in a document.
>>>
>>> What, exactly, are you trying to achieve?
>>>
>>> --
>>> Cheers
>>> macropod
>>> [Microsoft MVP - Word]
>>>
>>>
>>> "Janine" <janine(a)ribbonspace.com> wrote in message
>>> news:DB476098-476B-43F0-85E9-EB065E1087EC(a)microsoft.com...
>>>> Below does not purge trailing space in a table:-
>>>>
>>>> Fred Smith trailing space (no merge cells and anywhere in table rows)
>>>>
>>>> What vba do tables require to clean up properly please?
>>>>
>>>> Many thanks.
>>>>
>>>> Sub Purge_Trailing_Space()
>>>> Dim s As String
>>>> With ActiveDocument
>>>> If Len(.Range) = 1 Then Exit Sub
>>>> s = .Characters.Last.Previous
>>>> While s = " " Or s = Chr(13) Or s = Chr(11)
>>>> .Characters.Last.Previous = ""
>>>> s = .Characters.Last.Previous
>>>> Wend
>>>> End With
>>>> End Sub
>>>>
>>>>
>>>
>
>