Sign in to follow this  
Followers 0
polps

Cells.Find excel method

7 posts in this topic

Hello all,

I want to search for a string (inside a excel sheet)using the method Cells.Find

Looking the VBA code I found this:

Cells.Find(What:="text", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) _
        .Activate

How this code can to be traduced in AutoIT?

Tanks

Gianluca

Share this post


Link to post
Share on other sites



Something like:

#include <Excel.au3>

$sFilePath1 = @ScriptDir & "\Test1.xls"
$oExcel = _ExcelBookOpen($sFilePath1)
$oExcel.Cells.Find("text",Default, $xlValues, $xlPart, $xlByRows, $xlNext).Activate

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Traduced: Humiliated or disgraced by malicious and false statements

??? :) ???

Assuming you meant "Translated", try:

.Cells.Find('What:="text", After:=' & $ActiveCell & ', LookIn:=' & $xlValues & ', LookAt:=' & $xlPart & ', SearchOrder:=' & $xlByRows & ', SearchDirection:=' & $xlNext & ', MatchCase:=' & False).Activate

You have to track down the values for the variables (like $xlValues) if they are not already declared in Excel.au3, but I think other examples of this have been posted.

:(

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Traduced: Humiliated or disgraced by malicious and false statements

Traduced... I'm sorry for my poor english! Yes I meant Translated...

Thanks to you, the following code seems to work, but still remains an odd behaviour.

If the same string are written in more cells, the code jump directly on the last cell, so it find only the last occurence.

This is strange; i want search for the next cell (that contains the string) after the active cell, not for the last cell!

Any idea? Thanks a lot again.

$oExcel = _ExcelBookOpen($ExcelFile)
$oExcel.Range("A1").Activate
$sFindWhat = "text"
$oExcel.Cells.Find($sFindWhat, $oExcel.ActiveCell, $xlValue, $xlPart, $xlByRows, $xlNext, False).Activate
MsgBox (0,"",$oExcel.ActiveCells.Address)

Share this post


Link to post
Share on other sites

I'm pretty sure it's the "After:=ActiveCell" part, which doesn't work as expected. Don't have Excel here, so I can't test anything. Sorry.

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

This is a small example from my scripts that shows how to simply use find:

With $oExcel.ActiveSheet.Range ("A1:M200")

$c = .Find ("Some text")

EndWith

Share this post


Link to post
Share on other sites

Assuming you meant "Translated", try:

.Cells.Find('What:="text", After:=' & $ActiveCell & ', LookIn:=' & $xlValues & ', LookAt:=' & $xlPart & ', SearchOrder:=' & $xlByRows & ', SearchDirection:=' & $xlNext & ', MatchCase:=' & False).Activate

Thanks for this tip, I've been looking for ages for a way to pass stuff to VBA using the Key:=Value syntax.

I've been using this, which is a pain to read:

.Find("", Default, Default, $xlWhole)

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0