anthonyjr2 Posted August 11, 2016 Share Posted August 11, 2016 I'm having a lot of trouble getting the rows in my spreadsheet to get into an array. I've done this a million times with a single column, but for some reason the same syntax doesn't transfer over easily when using rows. Previously I used $aArray = _Excel_RangeRead($oExcel, Default, $oExcel.ActiveSheet.UsedRange.Columns("A:A")) To grab everything from the first column so I could use it. I don't really know how to do this for an entire row, and even when I might have gotten it, the UBound for my spreadsheet was turning out to be 1. For example, trying to get the row into an array by doing: $oExcel.ActiveSheet.Range("A" & $i+1).EntireRow.Select $aArray = _Excel_RangeRead($oExcel, Default, $pExcel.Selection) gives me a UBound on $aArray of 1, even though my spreadsheet has over 30 columns in that row. Can anyone tell me what I'm doing wrong? Thanks a bunch! UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
water Posted August 11, 2016 Share Posted August 11, 2016 $aArray = _Excel_RangeRead($oExcel, Default, $oExcel.ActiveSheet.UsedRange.Rows("1:1")) reads row 1 into a 2D array with a single row. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
anthonyjr2 Posted August 12, 2016 Author Share Posted August 12, 2016 (edited) 18 hours ago, water said: $aArray = _Excel_RangeRead($oExcel, Default, $oExcel.ActiveSheet.UsedRange.Rows("1:1")) reads row 1 into a 2D array with a single row. That doesn't seem to be working for me. When I check the UBound of the resulting array, it returns a size of 1 even though I have around 30 columns. Edited August 12, 2016 by anthonyjr2 UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
water Posted August 12, 2016 Share Posted August 12, 2016 What do you get with? This returns the number of columns in the array. MsgBox(0, "UBound", UBound($aArray, 2)) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
anthonyjr2 Posted August 12, 2016 Author Share Posted August 12, 2016 Oh wow, I completely misunderstood how arrays worked in autoit. I was using ConsoleWrite(UBound($aArray, 0) & @LF) because I wanted to access the subscripts, I didn't think it would import it as columns in the array. Using your flag makes it show up correctly. How can I go about accessing the elements of the array now? I was trying to just use $aArray[$i] where i is the index. UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
water Posted August 12, 2016 Share Posted August 12, 2016 3 minutes ago, anthonyjr2 said: I was trying to just use $aArray[$i] where i is the index. Do you get the expected result? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
anthonyjr2 Posted August 15, 2016 Author Share Posted August 15, 2016 On 8/12/2016 at 0:16 PM, water said: Do you get the expected result? No, I didn't. When I try to access it using the index I get a "Subscript dimension range exceeded." UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
water Posted August 15, 2016 Share Posted August 15, 2016 Can you please run _ArrayDisplay($aArray) after _Excel_RangeRead and post the result? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
anthonyjr2 Posted August 15, 2016 Author Share Posted August 15, 2016 Here's a picture of the output, I just crossed off the sensitive information. That does seem to be the information in row 1, so now I just don't know how to access it through a variable. Another quick question, how can I go about accessing rows based off of a variable? Like if I want to access row $j, I can't seem to figure out how to do it in the same style as: $oExcel.ActiveSheet.UsedRange.Rows("1:1") UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
water Posted August 15, 2016 Share Posted August 15, 2016 The result is a 2D array with just a single row. That's what [1][137] at the bottom of the ArrayDisplay tells you (1 row, 137 columns). To access the first column use: $aArray[0][0] that's because counting rows and columns starts with 0. So the highest row index is 0, and the highest column index is 136. To use a variable I suggest: $oExcel.ActiveSheet.UsedRange.Rows($j & ":" & $j) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
anthonyjr2 Posted August 15, 2016 Author Share Posted August 15, 2016 3 minutes ago, water said: The result is a 2D array with just a single row. That's what [1][137] at the bottom of the ArrayDisplay tells you (1 row, 137 columns). To access the first column use: $aArray[0][0] that's because counting rows and columns starts with 0. So the highest row index is 0, and the highest column index is 136. To use a variable I suggest: $oExcel.ActiveSheet.UsedRange.Rows($j & ":" & $j) Awesome! Thanks a bunch for the quick answers water! Both of those answers were exactly what I was looking for. UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
water Posted August 15, 2016 Share Posted August 15, 2016 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now