URGENT! Range.find not working...

J

Jorge Ribeiro

Hello

I've an urgent question

I need to find a string in a range but only inside it
So far i've been using

Excel.Range result = range.Find(dataToSearch,
Type.Missing,
Type.Missing,
Excel.XlLookAt.xlWhole,
Excel.XlSearchOrder.xlByRows,
Excel.XlSearchDirection.xlNext,
Type.Missing,
Type.Missing,
Type.Missing);

whre dataToSearch is my string to find, and range is where i want to find it.

this does not work because if it can't find a string in my range it
continues to
search in the rest of the sheet.
I tried several times with several parameters and the result was the same...

onde i definied my range to be only one cell X11 and then look for "2" in
it...
my range didn't had that value in it but the above command returned another
range pointing to CA11 where it had value "2" in it.

I need urgently to find a valur only inside a range not in all sheet space

please help me here
its really urgent

Regards, Jorge
 
P

PA

if you have only one cell selected, Excel search trough the whole sheet. You
could had a check before you use the Find method (untested):

if range.cells.count=1 then
if range=DataToSearch then
set result=range
end if
else
set result=range.find....
end if

by the way, I wouldn't name my variable "range" because this name is already
used be VBA which may lead to problem. Use something like

dim rngSearchArea as range

p-a
 

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