SkysLastChance

[Solved] _Excel_RangeFind Questions

19 posts in this topic

#1 ·  Posted (edited)

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



#2 ·  Posted

@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

#3 ·  Posted

@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

#4 ·  Posted

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

#5 ·  Posted

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

#7 ·  Posted

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

#9 ·  Posted

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

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

#11 ·  Posted

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

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

#13 ·  Posted

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#14 ·  Posted

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

#15 ·  Posted

I suggest function _ArrayDisplay. 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#16 ·  Posted

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

#17 ·  Posted

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

#18 ·  Posted (edited)

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

#19 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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

    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have to store an entire row of a Excel workbook into an array.  The row index is stored in a variable.
      How can i do it?
      Thanks in advance for your support.
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have to write a value into an excel column.
      I know where it starts from, but i don't know what the end is, last non-empty cell.
      How can i get the number of last non-empty cell?
      Thanks in advance.
      Regards 
    • Nareshm
      By Nareshm
      Hi All,
      I have excel file like this
      and i want to cut cell/text from excel to other software.

       
      I have to cut the cell of B column one by one and past into other software
      If Winexists("No Data Found")
      then restore cuted cell and goto next/down side cell
      How to do it ?
    • water
      By water
      Extensive library to control and manipulate Microsoft Excel charts.
      Theads: General Help & Support - Example Scripts
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2017-07-21)
      None. The COM error handling related bugs have been fixed.
       
    • Mag91
      By Mag91
      Hey Community,
      cause im too new in the Auto it world i will try it with the your help. hopefully.
      I woud like to know how i can handle my Problem.
      ----
      I have a Excel Data with 362 random numbers.
      For Example:
      1166642335374 1172899897343
      .....
      this numbers are a part of the filepath ...example
      D:\Projekte\1166_64233_5374
      as u can see its the first number of the Excel data. After the first 4 numbers it shoud make a "_" than another 5 "_"
      This is my first question. How can i handle this to make it Shell execute.
       
      --------
      Second question:
      If i am in the path.
      For Example:
      D:\Projekte\1166_64233_5374
      the code shoud search for specific PDF Files.
      They are named like: 0050569E364B1ED79B900F73E62660EC.pdf
      the first 15 letters are always the same
      0050569E364B1ED
      when he found this data he has to copy it on a Folder on the Desktop.
      (There can also be 2 or 3 pdfs in one Folder with this letters)
      ----
      Please give me some help :-)