ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   [Range].Find Help (https://www.excelbanter.com/excel-programming/390993-%5Brange%5D-find-help.html)

Dan R.

[Range].Find Help
 
I'm using the following to search for values on each sh, if/when found
it copies values back to the activesheet. But if the value is in
multiple columns it sometimes uses that value instead. Since it's
only supposed to search in column 3 why would it even find that value
in the first place?

With sh
xEnd = .Cells(Rows.count, 3).End(xlUp).Row
Set xRng = .Range(.Cells(2, 3), .Cells(xEnd, 3))
End With

Set rng = xRng.Find( _
What:=i.Value, _
LookIn:=xlValues, _
MatchCase:=False)

Thanks,
-- Dan


Dave Peterson

[Range].Find Help
 
I've never seen .find work that way.

Maybe it's time to double check to see what was found:

after the "set rng = xRng.find(...)" stuff:

if rng is nothing then
msgbox "not found"
else
msgbox rng.address & vblf & xrng.address
end if

===
Maybe it's picking up a partial match that you don't expect.

I would specify all the parms for that .Find() statement. If you don't, then
excel/VBA will use what was ever last used (either in code or by the user). And
that may not be what you want.

"Dan R." wrote:

I'm using the following to search for values on each sh, if/when found
it copies values back to the activesheet. But if the value is in
multiple columns it sometimes uses that value instead. Since it's
only supposed to search in column 3 why would it even find that value
in the first place?

With sh
xEnd = .Cells(Rows.count, 3).End(xlUp).Row
Set xRng = .Range(.Cells(2, 3), .Cells(xEnd, 3))
End With

Set rng = xRng.Find( _
What:=i.Value, _
LookIn:=xlValues, _
MatchCase:=False)

Thanks,
-- Dan


--

Dave Peterson

Dan R.

.Find Help
 
I'm sure the problem lies somewhere in the rest of my code but I
figured I'd ask. Thanks again Dave.

-- Dan



All times are GMT +1. The time now is 11:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com