Find Cell Marker in Table

C

Cathy D.

A lot of the templates I make are tables and after the information is merged
into the tables, I usually create a macro to clean up the information. The
one thing I can't seem to figure out, or don't know if there is a way to do
it, is to search for a cell marker within a table. I want to be able to
search for a character and a cell marker (e.g., paragraph mark followed by
cell marker), then be able to delete the paragraph mark and put the cell
marker back. If I just search for the paragraph marker, it will find all of
them in the file, rather than just the ones that are next to a cell marker.
I've needed to be able to do this so many times in the past, but have never
been able to figure out how. Any help will be greatly appreciated.

Cathy
 
J

Jean-Guy Marcil

Cathy D. was telling us:
Cathy D. nous racontait que :
A lot of the templates I make are tables and after the information is
merged into the tables, I usually create a macro to clean up the
information. The one thing I can't seem to figure out, or don't know
if there is a way to do it, is to search for a cell marker within a
table. I want to be able to search for a character and a cell marker
(e.g., paragraph mark followed by cell marker), then be able to
delete the paragraph mark and put the cell marker back. If I just
search for the paragraph marker, it will find all of them in the
file, rather than just the ones that are next to a cell marker. I've
needed to be able to do this so many times in the past, but have
never been able to figure out how. Any help will be greatly
appreciated.

THe cell marker is actually two character: Chr(13) and Chr(7). YOu can test
this with this little macro:
'_______________________________________
Sub CellContent()

Dim CellText As String
Dim CelLen As Long

CellText = Selection.Range.Text

CelLen = Len(CellText)

For i = 1 To CelLen
MsgBox "Character # " & i & " is " _
& "Chr(" & Asc(Mid(CellText, i, 1)) & ")"
Next

End Sub
'_______________________________________

Select a cell and its content and run the macro. Choose one that has only a
few characters and that whose last one is a ¶.

You notice that the last three characters are Chr(13) (the ¶) and
Chr(13)+Chr(7) (the ¤).
So you could write a macro to used VB string manipulation and test each cell
content, if you find Chr(13) Chr(13) Chr(7) , then remove the first Chr(13)
of the two. Or, you could use a little macro such as this one:

'_______________________________________
Sub RemoveLastParMark_in_Cell()

Dim CellRage As Range
Dim MyTable As Table
Dim MyCell As Cell

Application.ScreenUpdating = False

With ActiveDocument
For Each MyTable In .Tables
For Each MyCell In MyTable.Range.Cells
Do While MyCell.Range.Characters.Last.Previous = Chr(13)
MyCell.Range.Characters.Last.Previous.Delete
Loop
Next
Next
End With

Application.ScreenRefresh
Application.ScreenUpdating = True

End Sub
'_______________________________________

I am sure someone will be along shortly with an even faster way of doing
this, but at the moment this all my little brain can concoct!

Cheers.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Cathy D.

Hi Jean-Cuy,

Where can I get a list of what all the character numbers are. For instance,
you state that the paragraph mark is Chr 13. I would also like to know what
Chr number the comma is??

By the way, thank you very much for your help.
 
J

Jean-Guy Marcil

Cathy D. was telling us:
Cathy D. nous racontait que :
Hi Jean-Cuy,

Where can I get a list of what all the character numbers are. For
instance, you state that the paragraph mark is Chr 13. I would also
like to know what Chr number the comma is??

By the way, thank you very much for your help.


Look up ASCII in the online Help, or

select the character you want and run

Dim CharacterCode as Long
CharacterCode = Asc(Selection.Text)
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Martin Seelhofer

Hey there
[...]
select the character you want and run

Dim CharacterCode as Long
CharacterCode = Asc(Selection.Text)

Or simply type the following into the immediate window in
the VBA-Editor (if it is not displayed, press CTRL + G when
the VBA-Editor is open):

?Asc(Selection.Text)


Cheers,
Martin (who loves the immediate window!)
 
J

Jean-Guy Marcil

Martin Seelhofer was telling us:
Martin Seelhofer nous racontait que :
Hey there
[...]
select the character you want and run

Dim CharacterCode as Long
CharacterCode = Asc(Selection.Text)

Or simply type the following into the immediate window in
the VBA-Editor (if it is not displayed, press CTRL + G when
the VBA-Editor is open):

?Asc(Selection.Text)


Cheers,
Martin (who loves the immediate window!)

You are so right. I have to start using the Immediate window... Never think
about it. Thanks for the reminder!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Klaus Linke

Sorry for another reminder: Use AscW instead of Asc... That old function won't work for codes above 255.

:) Klaus

Martin Seelhofer was telling us:
Martin Seelhofer nous racontait que :
Hey there
[...]
select the character you want and run

Dim CharacterCode as Long
CharacterCode = Asc(Selection.Text)

Or simply type the following into the immediate window in
the VBA-Editor (if it is not displayed, press CTRL + G when
the VBA-Editor is open):

?Asc(Selection.Text)


Cheers,
Martin (who loves the immediate window!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top