Jump to content

[Solved] _Excel_RangeFind Questions


Recommended Posts

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

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

  • Moderators

@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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@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.  

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I suggest function _ArrayDisplay. 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

×
×
  • Create New...