Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Match Entire Excel CELL using find, not just the value 1

Status
Not open for further replies.

Damed

IS-IT--Management
May 24, 2005
7
CA
Hi All,

I've spent the better part of the day working on this, and it's working great except for 1 small issue (well, it's a large issue to the end result but a small code issue).

What I am doing is comparing the values in column1 of an excel file, then searching column 3 of a second excel file for that value, and if it matches return column 4 of the second file.

The code works great, except it's matching on any appearance of that value, and not the exact value only.

What I mean is that if column1 has a value of "2", I need it to match ONLY "2" in the second file. Currently, it is returning anything with a "2" in it.

So 22, 122, 102, etc are all coming back as matches, when I want only "2".

Now I know in Excel VBA you can use lookin:=xlWhole as a flag for the find command to achieve this - however I have been unable to reproduce this function using vbscript.



relevant code:

trialacct = objSheet.Cells(intRow, 1).value

set objRange = objSheet3.UsedRange
set objTarget = objRange.Find(trialacct)


That code works for looking up the value in column 1 of sheet one, then finding it in the second file (sheet3). But again, it's matching against any appearance of that value, when I want it to match the exact value. So "2" should only return "2" and not "22" as a match.

Hope this makes sense, and I really hope someone can help me out in finishing this off!


 

hi,
ExcelVBA_Help said:
expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)

LookAt Optional Variant Can be one of the following XlLookAt constants: xlWhole or xlPart.
Code:
set objTarget = objRange.Find(trialacct,,,1)


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks Skip - that was exactly what I needed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top