l3ill

_Excel_RangeFind '$iLookIn' Parameter - examples

8 posts in this topic

Cheers,

Hit a snag automating some excel stuff and I think this parameter could be what I need. Unfortunately cant find any examples/instructions on how to use it.

A shove in the right direction would be greatly appreciated. ;)

$iLookIn    [optional] Specifies where to search. Can be any of the XLFindLookIn enumeration (default = $xlValues)

Bill

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you look at the Excel Constants it says:

Quote


; XlFindLookIn Enumeration. Specifies the type of data to search.
; See: http://msdn.microsoft.com/en-us/library/ff822180(v=office.14).aspx
Global Const $xlComments = -4144 ; Comments
Global Const $xlFormulas = -4123 ; Formulas
Global Const $xlValues = -4163 ; Values

Edit: what are you looking for?  Maybe some more info on the problem?

Edited by Jfish
1 person likes this

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

But what are you then looking for?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I was hoping for a parameter that would limit the search range,  for instance as a variable given from a previously found range.

I have a large excel sheet (made from a  PDF) with financial statements with information that will always be in a different row.

I need to search for a Facility and in that facility search for several different titles; sales, dop, income, depreciation...  and then grab cell info (numbers).

So basically limit the search range for the titles to whatever area of the worksheet  "name your Facility" is filling. The 'facility area' was the variable I was hoping to pass on to the range_find as a variable to search for those titles in each facility , one facility at a time.

Hope that makes sense...

Thanks for your interest :) 

 

 

Share this post


Link to post
Share on other sites

Can you please post an (anonymized) sample of your data? Maybe setting a filter is all you need?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Just an FYI,

I ended up finding a way to get this done:

I had to set it up to find the first occurrence (there are 3) of the name of the first fac. and the first occurrence of the second fac. (-1)

Which gives me the chunk I was needing to pass on as a search criteria for the next section of code.

Spoiler
#Region  ; separates the facities in chunks for next step ($sFacRange) = A102:M196)=====working !!!

For $i = 0 To 10 ; loop through facilties
    ConsoleWrite("$aFacName[$i] = " & $aFacName[$i] & @CRLF)
;~  ConsoleWrite("$i) = " & $i & @CRLF)
    Local $aFacRange_First = _Excel_RangeFind($srcWorkbook, $aFacName[$i]) ; Find all cases of Fac (usually 3 for 3 pages)
    If $i <= 9 Then
    Local $aFacRange_Second = _Excel_RangeFind($srcWorkbook, $aFacName[$i + 1])
    Else
    ExitLoop
    EndIf

    Local $sInt01 = StringTrimLeft($aFacRange_First[0][2], 3) ;removes leading $A$ - leaving just number
    Local $aFacRange_First = "A" & $sInt01
    Local $sInt02 = StringTrimLeft($aFacRange_Second[0][2], 3) ;removes leading $A$ - leaving just number
    Local $sInt_02 = $sInt02 - 1
    Local $aFacRange_Second = "M" & $sInt_02
    Local $sFacRange = $aFacRange_First & ":" & $aFacRange_Second
    ConsoleWrite("$sFacRange) = " & $sFacRange & @CRLF)
#EndRegion ; separates the facities in chunks for next step ($sFacRange) = A102:M196)===working !!!

Next ; is further down in the code,  added for testing obviously wouldnt work w/out this ;-)

 

Excel file: imagine a large financial statement with 10 fac. each fac. has 3 sections.

every month they are in different cells with empty cells added randomly. (tons of empty or useless information cells)

 

Thanks again :)

Bill

 

Edit: An example of the console output:

Spoiler
$aFacName[$i] = Fac. 01
$i) = 0
$sFacRange) = A102:M196
$aFacName[$i] = Fac. 02
$i) = 1
$sFacRange) = A197:M287
$aFacName[$i] = Fac. 03
$i) = 2
$sFacRange) = A288:M370

 

 

Edited by l3ill

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

  • Similar Content

    • water
      Fixed versions of _Excel_RangeFind and _Excel_BookOpen for AutoIt > 3.3.12.0
      By water
      After AutoIt 3.3.12.0 the handling of COM errors has been "fixed".
      Now nested COM operations crash the script in case of an error even when there is a COM error handler.
      Here you find a fixed version of function _Excel_RangeFind. I simply removed all nestings and added the missing COM error hander:
       
      Another function that needed some modification is _Excel_BookOpen. It crashed when a workbook was opened using _Excel_BookOpen with parameter $bVisible = True, saved and then reopened. The following modification solves the problem:
      Please tell me if you still have problems with this or any other function from the Excel or Word UDF!
    • l3ill
      _Excel_RangeFind - requested action with this object has failed
      By l3ill
      Hi,
      anybody know what this is about?
      I have tried on three different PC's all give me the same error whether my own code or the Help File Examples...
      All other excel func's work fine. ( haven't tested them all but most)
      >Running:(3.3.14.2):C:\Users\XXXXX\Desktop\autoit-v3\install\autoit3.exe "C:\Users\XXXXX\Desktop\autoit-v3\install\Examples\Helpfile\_Excel_RangeFind[2].au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop "C:\Users\XXXXX\Desktop\autoit-v3\install\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][1] = $oMatch^ ERROR No script error to speak of just this Include error.
      Any help is greatly appreciated.
      Bill
    • hero88
      _Excel_RangeFind exits with an error
      By hero88
      Hi
      I have an issue with _ExcelRangeFind, i have a it working on another PC but on my pc i just gives me this error
      "d:\AutoIt3\Include\Excel.au3" (656) : ==> The requested action with this object has failed.:
      $aResult[$iIndex][1] = $oMatch.Name.Name
      $aResult[$iIndex][1] = $oMatch^ ERROR
      I have trimmed the script to the absolute minimum.
      What iy should do, I give it a number, It opens an excel file, and then it reads through coloumn A and then returns an array when it finds the number in Excel. The number is in coloumn A of the Excel sheet.
      The versions of autoit are the same on both machines.
      The Excel sheet opens correctly, but it crashes on the rangefind command. I have also tried this $NavisionIDFound = _Excel_RangeFind($Movielistsheet,$NavisionID,"A1:A10000",Default,$xlWhole,True), with the same result.
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <GuiButton.au3> #include <GuiComboBox.au3> #include <Excel.au3> ;Includes from source dir #include <_RecFileListToArray.au3> #include <_XMLDomWrapper.au3> $MovielistExcel = "h:\Movie list.xlsm" LoadDataFromMovieListSheet() Func LoadDataFromMovieListSheet() ConsoleWrite("Load Data From MovieList Sheet" & @LF) $NavisionID = 106266 ; Create application object $ExcelAppHandle = _Excel_Open(Default,Default,Default,Default,True) If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $Movielistsheet = _Excel_BookOpen($ExcelAppHandle, $MovielistExcel, True, Default) ;~ Read the formulas of a cell range (all used cells in column A) $NavisionIDFound = _Excel_RangeFind($Movielistsheet,$NavisionID,$Movielistsheet.ActiveSheet.Usedrange.Columns("A:A"),Default,$xlWhole,True)