Range.Find

A

AZ

I am having a problem with the following, can someone
rectify this for me.

Say, the doc. contains a table of 2 columns & 1 row. The
application declares a variable (lRange) of type Range,
pointing to Cell 1 of the table. When it runs the code
lRange.Find {other code}
should it find only the value within the range (in this
case cell 1 of the table)?

In my application it does not do this, if the value does
exist in cell 2 but not 1, it finds that instance.

regards
 
M

Mark Baird

The following code works fine for me.

Dim rCell As Range
Set rCell = ActiveDocument.Tables(1).Cell(1, 1).Range

With rCell.Find
.Text = "test"
.Replacement.Text = "1"
.Execute Replace:=wdReplaceAll
End With


Mark Baird
 
A

AZ

Thanks,

Say if "test" does not exist in cell(1,1) but exists in
cell(2,1). It should not find "test" as its not in the
range or should it?

regards
 
K

Klaus Linke

Say if "test" does not exist in cell(1,1) but exists in
cell(2,1). It should not find "test" as its not in the
range or should it?


Correct. Hard to say what the problem is without seeing your code.
It seems to work fine for me. The following macro will only give "True" if
"test" appears in cell(1,1).

Dim myRange As Range
' selection should be somewhere in the table
Set myRange = Selection.Tables(1).Cell(1, 1).Range
myRange.Find.ClearFormatting
With myRange.Find
.Text = "test"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
MsgBox myRange.Find.Execute
myRange.Select

Regards,
Klaus
 

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