Page 1 of 1 1
Topic Options
#92058 - 2003-05-20 11:49 AM Find Vaule for Excel
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Hi Everyone

OK check this line out and tell me what I am doing wrong, I want to search a range for a value, but the value must be excact.

E.G Search for Rich, and in the data I have Richard and Rich.

Well I want it to just pick up on the Rich, not the Richard.

code:
 
$SourceObjectRow = $ObjExcel.Range("A1:C2500").FindFindFind($SourceObject,,,xlWhole,,,,)

I get an expected expression! error.

It works fine if I don't want excact matches, by using:
code:
 
$SourceObjectRow = $ObjExcel.Range("A1:C2500").FindFindFind($SourceObject)

I quote from the microsoft.

quote:

expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase,úMatchByte)

LookAt Optional Variant. Can be one of the following XlLookAt constants: xlWhole or xlPart.

Thanks

Rich

Top
#92059 - 2003-05-21 12:39 AM Re: Find Vaule for Excel
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
How about...

code:
$SourceObjectRow = $ObjExcel.Range("A1:C2500").FindFindFind($SourceObject,,,$xlWhole,,,,)


Top
#92060 - 2003-05-20 01:07 PM Re: Find Vaule for Excel
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Sorry Chris for some reason when I posted it inserted FindFind.

Thanks for getting back

code:
$SourceObjectRow = $ObjExcel.Range("A1:C2500").Find($SourceObject,,,$xlWhole,,,,)

xlWhole is not a verable but a function within the .Find Command.

I think it should be:

code:
 $SourceObjectRow = $ObjExcel.Range("A1:C2500").Find($SourceObject,,,xlWhole=true,,,,)

Nope still don't work [Frown]

I think Shawn is an expert on this [Big Grin] .

Thanks

[ 20. May 2003, 13:09: Message edited by: Richard Farthing ]

Top
#92061 - 2003-05-20 02:38 PM Re: Find Vaule for Excel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Assign a boolean (True) to $xlWhole before using it in there ?
_________________________



Top
#92062 - 2003-05-20 02:42 PM Re: Find Vaule for Excel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Yalla :


$xlWhole = not 0
$SourceObjectRow = $ObjExcel.Range("A1:C2500").Find($SourceObject,,,$xlWhole,,,,)


{edit: somehow it added a 'findfind' [Roll Eyes] }

[ 20. May 2003, 14:51: Message edited by: Jochen ]
_________________________



Top
#92063 - 2003-05-20 02:54 PM Re: Find Vaule for Excel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Or how 'bout


$SourceObjectRow = $ObjExcel.Range("A1:C2500").Find($SourceObject,,,'xlWhole',,,,)


.... hmmm, no ! I don't think so, but worth a try anyways [Smile]
_________________________



Top
#92064 - 2003-05-20 03:57 PM Re: Find Vaule for Excel
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Thanks Jochen

I have tried your examples, but still no joy.

Just thinking about this xlWhole, if I do get it working, hope it don't match case because then I will be in trouble [Big Grin]

I will hunt through the M$ site for more clues.

Rich

Top
#92065 - 2003-05-20 04:20 PM Re: Find Vaule for Excel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
hehe,

was about to test with it but got hold up here [Wink]

Predictably it will be answered by Shawn anyway before we get even close [Roll Eyes]

{Whatever, all we need to know is how to rebuild a 'Variant' that represents xlLookAt constants with KiX [Eek!] }

[ 21. May 2003, 08:49: Message edited by: Jochen ]
_________________________



Top
#92066 - 2003-05-20 04:39 PM Re: Find Vaule for Excel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Found a VB sample on MSDN in which it is done like this :

code:
 Sub FindStrings()
Dim firstCell, nextCell, stringToFind As String
' Show an input box and return the entry to a variable.
stringToFind = _
Application.InputBox("String to find?", "Search String")
' Set an object variable to evaluate the Find command.
Set firstCell = Cells.Find(what:=stringToFind, lookat:=xlWhole, _
searchdirection:=xlPrevious)
' If the string is not found, show this message box.
If firstCell Is Nothing Then
MsgBox "Search Value Not Found.", vbExclamation
Else
' Otherwise, find the next occurrence of the search text.
nextCell = _
Cells.FindNext(after:=Range(firstCell.Address)).Address
' Show its address in a message box.
MsgBox nextCell
' Continue finding the next occurrence as long as the address of
' the found cell is not the same as the first cell.
Do While firstCell.Address <> nextCell
nextCell = Cells.FindNext(after:=Range(nextCell)).Address
MsgBox nextCell
Loop
End If
End Sub

Got to leave now, looking forward to see what you came up with [Razz]

[ 20. May 2003, 16:40: Message edited by: Jochen ]
_________________________



Top
#92067 - 2003-05-20 04:41 PM Re: Find Vaule for Excel
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hey Rich, does this help:

code:
$Row = $Excel.Range("A1:A5").Find("Rich",,-4163,2)

?"Value=" $Row.Value
?"Row=" $Row.Row
?"Column=" $Row.Column

-4163 means search by value (may be the default anyways) and 2 means xlPart. Dont forget that the search starts after the first cell specified in the range.
-Shawn

Top
#92068 - 2003-05-20 04:43 PM Re: Find Vaule for Excel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
[Eek!] [Eek!] [Eek!]

I KNEW THAT THIS WOULD HAPPEN [Big Grin]

2 is xlPart, eh ?
Just for the records, what is xlWhole then ?

[ 20. May 2003, 16:44: Message edited by: Jochen ]
_________________________



Top
#92069 - 2003-05-20 04:50 PM Re: Find Vaule for Excel
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Cappy [Wink]

xlWhole is 1

Best trick here is to use ObjectBrowser in Excel VBEditor ... it gives you all the enumerated constants and their assoc. hex values.

Top
#92070 - 2003-05-20 05:08 PM Re: Find Vaule for Excel
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
If I was a women I would have your baby [Big Grin] .

Nice 1

code:
$SourceObjectRow = $ObjExcel.Range("A1:C2500").Find("$SourceObject",,-4163,1) 

Thanks Shawn and Everyone that had input.

For future reference where do you get this information from, becuase on the M$ site it says the code is Lookat:=xlWhole.

Rich

[ 20. May 2003, 17:10: Message edited by: Richard Farthing ]

Top
#92071 - 2003-05-20 05:47 PM Re: Find Vaule for Excel
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hehee - yeah, just fire-up Excel and start Tools->Macro->VBEditor. Then go View->ObjectBrowser. In the ComboBox change "All Libraries"to "Excel". Scroll down to XLLookAt and note the right view showing the constants. Click on xlPart and you should see the value in the lower pane. This is using Office97.

[ 20. May 2003, 17:48: Message edited by: Shawn ]

Top
#92072 - 2003-05-20 06:45 PM Re: Find Vaule for Excel
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Thanks
Top
#92073 - 2003-05-21 08:54 AM Re: Find Vaule for Excel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Tsk,

Allthough completely wrong I was at least close:

Only thing it was boolean instead of integer [Roll Eyes]
_________________________



Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.074 seconds in which 0.034 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org