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  

Find&Replace character before end-of-cell mark



 
 
Thread Tools Display Modes
  #1  
Old September 22nd, 2008, 05:48 PM posted to microsoft.public.word.tables
[email protected]
external usenet poster
 
Posts: 3
Default Find&Replace character before end-of-cell mark

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?
  #2  
Old September 22nd, 2008, 06:31 PM posted to microsoft.public.word.tables
Suzanne S. Barnhill
external usenet poster
 
Posts: 31,786
Default Find&Replace character before end-of-cell mark

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

wrote in message
...
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?


  #3  
Old September 23rd, 2008, 04:56 AM posted to microsoft.public.word.tables
[email protected]
external usenet poster
 
Posts: 3
Default Find&Replace character before end-of-cell mark

On Sep 22, 10:31*am, "Suzanne S. Barnhill" wrote:
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.
  #4  
Old September 24th, 2008, 09:32 AM posted to microsoft.public.word.tables
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default Find&Replace character before end-of-cell mark

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

wrote in message
...
On Sep 22, 10:31 am, "Suzanne S. Barnhill" wrote:
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.


  #5  
Old September 24th, 2008, 03:32 PM posted to microsoft.public.word.tables
[email protected]
external usenet poster
 
Posts: 3
Default Find&Replace character before end-of-cell mark

On Sep 24, 1:32*am, "Doug Robbins - Word MVP"
wrote:
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

wrote in message

...
On Sep 22, 10:31 am, "Suzanne S. Barnhill" wrote: 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.


Thanks, Doug. Works beautifully.
  #6  
Old November 26th, 2008, 07:12 PM posted to microsoft.public.word.tables
Shane Gidley
external usenet poster
 
Posts: 1
Default Almost there

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?
  #7  
Old November 27th, 2008, 07:12 AM posted to microsoft.public.word.tables
Graham Mayor
external usenet poster
 
Posts: 18,297
Default Almost there

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

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Shane Gidley wrote:
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?



 




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 02:37 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.