Hi,
I am trying to loop through a table in a Word document to find certain text in column 1. If the text is found, the selection is extended into column 2 and both cells selected.
The resultant found text is destined for another table in the same document. The destination table is just a one row two column table ready for the found text. There will usually be more than one instance of the found text, so the destination table has to add rows as new text is found.
the following code works on the main table to find the required text.
Could anyone tell me how to do the above and extend the code for this purpose.
Regards,
'start the find process
For Each tCell In Selection.Cells
'search for x.x.x text
With Selection.Find
.MatchWildcards = True
.Format = True
.Forward = True
.MatchCase = False
.MatchWholeWord = False
.MatchSoundsLike = False
.Execute FindText:=" [0-9]@.[0-9]@.[0-9]@ "
End With
'if the selection is found then assign to table(2)
If Selection.Find.Found = True Then
Selection.Select
Selection.MoveRight wdCharacter, 2, wdExtend
tCellText = LTrim(Replace(Left(Selection.Range.Text, Len(Selection.Range.Text) - 2), Chr(13), ""))
'Do something to assign to the destination table
End If
'move down to next row and continue search
Selection.Move wdRow, 1
Next
End With
I am trying to loop through a table in a Word document to find certain text in column 1. If the text is found, the selection is extended into column 2 and both cells selected.
The resultant found text is destined for another table in the same document. The destination table is just a one row two column table ready for the found text. There will usually be more than one instance of the found text, so the destination table has to add rows as new text is found.
the following code works on the main table to find the required text.
Could anyone tell me how to do the above and extend the code for this purpose.
Regards,
'start the find process
For Each tCell In Selection.Cells
'search for x.x.x text
With Selection.Find
.MatchWildcards = True
.Format = True
.Forward = True
.MatchCase = False
.MatchWholeWord = False
.MatchSoundsLike = False
.Execute FindText:=" [0-9]@.[0-9]@.[0-9]@ "
End With
'if the selection is found then assign to table(2)
If Selection.Find.Found = True Then
Selection.Select
Selection.MoveRight wdCharacter, 2, wdExtend
tCellText = LTrim(Replace(Left(Selection.Range.Text, Len(Selection.Range.Text) - 2), Chr(13), ""))
'Do something to assign to the destination table
End If
'move down to next row and continue search
Selection.Move wdRow, 1
Next
End With