Jump to content

Basic Array Error working with Excel! Please help!

Recommended Posts

I am a super noob at AutoIt so bare with me.

Here is my code:

      ;Define the Variables entered in Previous Table
      $ItemOut = GUICtrlRead($ItemOutID)
      $NumItemOut = GUICtrlRead($NumItemOutId)
      $Who = GUICtrlRead($WhoId)
      $Where = GUICtrlRead($WhereID)

      ;Set the filepath to the excel documents
      $fPath ="P:\IT_Interns\Projects\Inventory Project\Inventory.xlsx"
      ;Open a specific Excel window
      $app = _Excel_Open()
      ;Wait till that window has opened and is active
      ;Open the workbook we are using with the given filepath
      $Excel = _Excel_BookOpen( $app, $fPath, Default, Default, True)

      Global $array = _Excel_RangeFind($Excel, $ItemOut, Default, Default, $xlWhole)
      $arrayData = $array[2]

The problem is with the last line of code and reads: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

How is this possible?

The array is created and assigned to _Excel_RangeFind function which returns 6 values, I am trying to only obtain the 3rd value which is the address of the specific cell, so $array[2] should access the third value in the array; but it throws the error! I ran _ArrayDisplay and it runs fine showing the full 6 values so I know the array Range Find did work and input the values.



Link to post
Share on other sites


The function returns a 2D array thus your subscript error.  Try this

$arrayData = $array[2][3] ; to get value of the cell


edit: Welcome to the forum.  Please use the code tags when posting code.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to post
Share on other sites

Thank you so much for the responses! That was exactly it I cannot believe I missed that in the AutoIt Help menu. The location of what I was looking for was in $array[0][2], I have no idea why they input all of the data within the 0th 1st part of the array, they should just put it within a 1D array but nonetheless thank you! Now I just need to find out how to parse through the data to get the next cell over. If it returns A2 I need it to receive the data within B2 cell. I'll post about that on a separate post though!

Link to post
Share on other sites

If you always need the content of the cell one column to the right then I would use:

$vResult = $oWorkbook.Range($ItemOut).Offset(0, 1).Value


My UDFs and Tutorials:


Active Directory (NEW 2021-06-05 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version - Download
Outlook Tools (2019-07-22 - Version - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version - Download - General Help & Support - Example Scripts
PowerPoint (NEW 2021-07-28 - Version - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version - Download - General Help & Support - Wiki

ADO - Wiki, WebDriver - Wiki


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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...