Jump to content
SkysLastChance

[Solved] _Excel_RangeFind Questions

Recommended Posts

SkysLastChance

My Main goal is to copy the info from sheet 2 and put it in the correct date and time location on sheet 1.

1.xlsm - Password 2007

2.xlsx

1. I do not understand why I am unable to find the date. I am reading the value and searching for the value. But, it never turns anything up.

2. What would be the best way (function) to go about selecting the second cell underneath the date after I have found it? 

So Ideally, I would want to match the date. Once it finds the date go 2 cells down insert the data from sheet 2. I believe I have a good idea on how to loop the script. The only thing I am not sure on is how to take the cell I find and get the cell location (exp. A2)  to go the cell that I find  and select 2 cells down and go to A4.

In other words I don't know how to put the cell I find into a variable that I can use to position where I start to input data. 

 

Any help is appreciated as always.

#include <Excel.au3>
#include <Array.au3>

MsgBox(0, "", "Open Excel 1")

Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)")

MsgBox(0, "", "Open Excel 2")

Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)")


If FileExists($sExcelFile2) Then
   Global $oExcel2 = _Excel_Open ()
    $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2)
EndIF


If FileExists($sExcelFile1) Then
   Global $oExcel1 = _Excel_Open ()
    $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007")
EndIF


$oRead = _Excel_RangeRead ($oExcel2,Default,"A2")
$oRead1 = _Excel_RangeRead($oExcel1,Default,"BY4")
MsgBox  (0,"Test",$oRead)
MsgBox  (0,"Test",$oRead1)

$oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD4")

If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
    Local $aSalesResult = _Excel_RangeFind($oExcel1, $oRead, Default, Default, $xlWhole)
    _Arraydisplay($aSalesResult, "RangeFind", 2, 0, "", "|", "Col|Sheet|Name|Cell|Value|Formula|Comment")
EndIf

 

Edited by SkysLastChance

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
JLogan3o13

@SkysLastChance how is this different than your other Excel thread, which water has already been active in? If it is a continuation of the same issue (as it appears to be) I will merge the topics.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
SkysLastChance

@JLogan3o13I thought it would be better to start a new post because this has nothing to do with an error. Water solved my question; I just needed to update my UDF. I was not able to do any testing with _Excel_RangeRead. If you feel it is better merged by all means.  


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
JLogan3o13

If it is different that is fine - you simply seemed to be asking about getting the date in both threads.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
water

The range you specify is invalid.

$oFind = _Excel_RangeFind ($oExcel1,$oRead,"=E4:FD4")

Use:

$oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD4")

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SkysLastChance

I must of done that when I was setting up the example. Thank you for catching this though. It is still not finding the date. 

Edited by SkysLastChance

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

This article explains why you need to use the displayed date for _Excel_RangeFind: http://www.ozgrid.com/VBA/find-dates.htm

So your example should look like:

#include <Excel.au3>
#include <Array.au3>

MsgBox(0, "", "Open Excel 1")

Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)")

MsgBox(0, "", "Open Excel 2")

Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)")

If FileExists($sExcelFile2) Then
   Global $oExcel2 = _Excel_Open ()
    $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2)
EndIF

If FileExists($sExcelFile1) Then
   Global $oExcel1 = _Excel_Open ()
    $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007")
EndIF

$oRead = _Excel_RangeRead ($oExcel2,Default,"A2", 3) ; <== Line changed!!
$oRead1 = _Excel_RangeRead($oExcel1,Default,"BY4")
MsgBox  (0,"Test",$oRead)
MsgBox  (0,"Test",$oRead1)

$oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD4")

If @error Then
    MsgBox(4096, "", "No File(s) chosen")
Else
    Local $aSalesResult = _Excel_RangeFind($oExcel1, $oRead, Default, Default, $xlWhole)
    _Arraydisplay($aSalesResult, "RangeFind", 2, 0, "", "|", "Col|Sheet|Name|Cell|Value|Formula|Comment")
EndIf

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SkysLastChance

Thank you, Water

Dates in Excel are so complicated. XD

How do I display just the cell in a Msgbox?

 

Edited by SkysLastChance

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

Read the value of the cell using _Excel_RangeRead and display it ;) 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SkysLastChance

Sorry, I mean like displaying the cell, such as A1,B3,F5,etc.

or am I still able to accomplish this with _Excel_RangeRead? 

 

 

 


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

According to the help file the returned array contains the cell's address in element 2:

Quote
Success: a two-dimensional zero based array with the following information:
    0 - Name of the worksheet
    1 - Name of the cell
    2 - Address of the cell
    3 - Value of the cell
    4 - Formula of the cell
    5 - Comment of the cell

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SkysLastChance

I keep getting a blank Msgbox.

How do I get a return  value with multiple success outcomes?

Do I have to grab it from the array?

 


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

Correct. As the help file describes you always get a 2D array from _Excel_RangeFind.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SkysLastChance

I really appreciate the help as always. 

Here is what I came up with.

$aArray1 = _ArrayToString($aSalesResult, " :: ", 0, 0, @CRLF, 2,2)

MsgBox(0, "Cell Address",$aArray1)

 


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

I suggest function _ArrayDisplay. 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SkysLastChance

Not sure what I am doing wrong. When I try it with _ArrayDisplay I just get a 1. 

$aArray = _Arraydisplay($aSalesResult,"Cell Address","0:0|2:2",64)

MsgBox(0, "Cell Address",$aArray)

 


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
BrewManNH
8 minutes ago, SkysLastChance said:

When I try it with _ArrayDisplay I just get a 1. 

What were you expecting to see? Have you read the help file for the function?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
SkysLastChance

I now understand why I am seeing a 1 

I guess my question would be is how do I pull the elements from _Arraydisplay?

Also why is _ArrayDisplay better then

$aArray1 = _ArrayToString($aSalesResult, "", 0, 0, "", 2,2)

also is "$Clip = _ArrayToClip($aSalesResult,"",0,0,"",2,2) just as bad as _ArrayToString?"

Edited by SkysLastChance

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

Each of the _Array* functions has a unique goal.
_ArrayDisplay displays the content of an array in readable format.
_ArrayToClip copies the content of an array to the clipboard.
So which function to use depends on what you want to achieve.

None of the functions is better or worse as another one.

To access an array within your script just use the row and column index as you would do in Excel.
To access the "cell" in the 2nd line and 4th column use

$sCell = $aSalesResult[1][3]

Why 1 and 3? Because the index for rows and columns of an array starts with 0.

For further information please check the array tutorial in the wiki.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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

    • Skeletor
      By Skeletor
      Hi Guys,
      Can anyone point me in the right direction. I'm trying to accomplished conditional formatting with arrows, but the code I have is wrong... 
      .Range("=$A3:$A4000").FormatConditions.Add = (xlCellValue, xlGreater, "=$A:$A") .IconSet(xl3Arrows) ;ActiveWorkbook.iconsets I also tried it like this:
      .Range("=$A3:$A4000").FormatConditions _ .Add(xlCellValue, xlGreater, "=$A:$A") .IconSet(xl3Arrows) ;ActiveWorkbook.iconsets  
    • Skeletor
      By Skeletor
      Hi Guys,
      How would you use _Excel_FilterSet to filter the excel sheet from largest number to smallest number?
      _Excel_FilterSet($oWorkbook, "Sheet1", "A2:I2", 1, ">20", 1, "<40") ; OR _Excel_FilterSet($oWorkbook, "Sheet1", "A2:I2", 1, ">", 1, "<") Excel Sheet attached. Trying to filter on the last column "I2"
      Inventory.xlsx
    • Skeletor
      By Skeletor
      Hi All,
      Has anyone come across this before?
      Code below:
      $SheetList = _Excel_SheetList($oWorkbook) _FileWriteFromArray("C:\" & $SheetListOutput, $SheetList, 1) Result:
      ResultABC| ResultDEF| ResultGHI| ResultJKL| ResultMNO| It created these "|" vertical bars?
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
×