Find string in table and move to next cell

D

Debra Farnham

Hello All

Windows 2K
Word 2K

I'm trying to locate a string (strFWitnessName) in a table in my document
and then move one cell to the right to enter a page number.

strFWitnessName could appear in 1 of three tables in the document ( but it
will never appear in all three)

I do not want to search the entire document as strFWitnessName will appear
throughout the document text as well.


I found the following code posted by Doug Robbins and tried testing it but
apparently I am just not familiar enough with vba to understand what it is
doing.

Dim i As Integer, j As Integer, myrange As Range
For j = 1 To ActiveDocument.Tables.Count
For i = 1 To ActiveDocument.Tables(j).Rows.Count
Set myrange = ActiveDocument.Tables(j).Cell(i, 1).Range
myrange.End = myrange.End - 1
If myrange.Text = strFWitnessName Then
ActiveDocument.Tables(j).Cell(i, 2).Range.Text = "pagenumber1"
ActiveDocument.Tables(j).Cell(i, 3).Range.Text = "pagenumber2"
End If
Next i
Next j

Any help would be greatly appreciated.

TIA

Debra
 
D

Debra Farnham

I found the problem

I had to trim the string in order to find it.

Doug's code now works like a charm.

Thanks for taking the time to review my post.


Debra
 

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