Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Look for text in a cell and then if found put other text in next c

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Novice - 09 Dec 2004 07:07 GMT
Hey all, does anyone know of a way to look for "some text" in a cell in a
table, then move to the cell to the right of that cell and put "some other
text"?

I have the following - but it sometimes puts the "some other text" twice:
With ActiveDocument.Content.Find
   .ClearFormatting
   Do While .Execute(FindText:="some text", Forward:=True, _
           Format:=True) = True
       'Selection.Delete
       Selection.SelectCell
       Selection.MoveRight
       'With .Parent
       With .Parent
           .StartOf Unit:=wdParagraph, Extend:=wdMove
           .Move Unit:=wdCell, Count:=1
           .InsertAfter "some other text"
           .Move Unit:=wdCell, Count:=1
       End With
   Loop
End With

Also, ideally I would like to delete that "some text" first and then move to
the cell to the right and put "some other text".  You can see where I have
deleted that portion of the code - because that just totally messed things up.

Thanks,
Novice
Doug Robbins - 09 Dec 2004 10:42 GMT
Try this:

Dim arange As Range, i As Long, j As Long
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
   Do While .Execute(FindText:="some text", Forward:=True) = True
           Set arange = Selection.Range
           i = arange.Information(wdEndOfRangeRowNumber)
           j = arange.Information(wdEndOfRangeColumnNumber)
           Selection.Tables(1).Cell(i, j + 1).Range.InsertAfter "Some other
text"
           Selection.Tables(1).Cell(i, j).Range.Delete
   Loop
End With

If "some text" is in the last column, it would need some modification to
insert "Some other text" in the first cell in the next row, but I am
assuming that is not the case.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Hey all, does anyone know of a way to look for "some text" in a cell in a
> table, then move to the cell to the right of that cell and put "some other
[quoted text clipped - 26 lines]
> Thanks,
> Novice
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.