Find&Replace character before end-of-cell mark

B

BrianHolfield

Find “AnytextA*” Replace “Anytext*”, where * represents the end-of-
cell marker. Parallel to replacing a character before ^p. Should be
dead simple, but apparently it aint. How to do it?
 
S

Suzanne S. Barnhill

Unfortunately, MS has not (yet) provided any way to search for an
end-of-cell marker.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Find “AnytextA*” Replace “Anytext*”, where * represents the end-of-
cell marker. Parallel to replacing a character before ^p. Should be
dead simple, but apparently it aint. How to do it?
 
B

BrianHolfield

Unfortunately, MS has not (yet) provided any way to search for an
end-of-cell marker.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Yes, that much is clear. But isn’t there a programmatic approach? I
imagine saying: read the contents of a cell into variableX; right
truncate variableX by one character; paste variableX back into the
cell.
 
D

Doug Robbins - Word MVP

Use a macro containing the following code when the selection is in the table

Dim arng As Range
Dim i As Long, j As Long
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set arng = .Cell(i, j).Range
arng.End = arng.End - 1
If Right(arng.Words.Last, 1) = "A" Then
arng.Words.Last = Left(arng.Words.Last,
Len(arng.Words.Last) - 1)
End If
Next j
Next i
End With


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

Unfortunately, MS has not (yet) provided any way to search for an
end-of-cell marker.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Yes, that much is clear. But isn’t there a programmatic approach? I
imagine saying: read the contents of a cell into variableX; right
truncate variableX by one character; paste variableX back into the
cell.
 
B

BrianHolfield

Use a macro containing the following code when the selection is in the table

Dim arng As Range
Dim i As Long, j As Long
With Selection.Tables(1)
    For i = 1 To .Rows.Count
        For j = 1 To .Columns.Count
            Set arng = .Cell(i, j).Range
            arng.End = arng.End - 1
            If Right(arng.Words.Last, 1) = "A" Then
                arng.Words.Last = Left(arng.Words.Last,
Len(arng.Words.Last) - 1)
            End If
        Next j
    Next i
End With

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





Yes, that much is clear. But isn’t there a programmatic approach? I
imagine saying: read the contents of a cell into variableX; right
truncate variableX by one character; paste variableX back into the
cell.

Thanks, Doug. Works beautifully.
 
S

Shane Gidley

This code looks great to remove every day characters, but the problem I have and that a lot of others on the web seem to have but cannot find answers to is how to remove a blank line at the end of the cell, or ^p. I tried replacing the "A" with "^p" of course, but it didn't work.
Any ideas for this?
 
G

Graham Mayor

Replace "A" with Chr(13) - no quotes

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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