Sign in to follow this  
Followers 0
Myicq

[Solved] Excel - range error if check against wrong type ?

1 post in this topic

#1 ·  Posted (edited)

Discovered a strange thing today with Excel. Maybe it's just me doing something wrong.

Here's the situation: Excel sheet containing 18 columns by 1700 rows.

For this example, column no. 12 ("M") contains a number. Column 13 ("N") has a number or a text.

I can open the book just fine.

Now I can try:

$a = _Excel_RangeRead($e, 1, "A1:R1700", 1)
for $i = 1 to 1700
    if $a[$i][13] = "XXX" then
        ConsoleWrite("found at " & $i & @LF)
    EndIf
Next

This will work fine, and list all lines containing "XXX".

If I change only the 13:

$a = _Excel_RangeRead($e, 1, "A1:R1700", 1)
for $i = 1 to 1700
    if $a[$i][12] = "XXX" then
        ConsoleWrite("found at " & $i & @LF)
    EndIf
Next

I get an error about the array.

"file.au3" (30) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
if $a[$i][12] = "XXX" then
if ^ ERROR

But I KNOW that the array is correct size, I am only reading a different column. Changing 12 to 11, another mixed column, and it will work.

What did I miss - why can't I check a number against "XXX" string ? After all I know, it should just fail, like "if 3= 'XXX' then ..."

 

EDIT: well, I guess it's real embaressing: I think I messed up the 0 or 1-based array.  :

This topic may be deleted if admins see fit.. otherwise marked solved.

Edited by Myicq

I am just a hobby programmer, and nothing great to publish right now.

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
Sign in to follow this  
Followers 0

  • Similar Content

    • VeryGut
      By VeryGut
      I'm trying to insert the following formula in cell A2 using my script:
      =if(A1=""; "YES"; "NO")
      To my understanding, the line of code should be similar to this:
      _Excel_RangeWrite($MasterFile, Default, "=if(A1=""; "YES"; "NO")", "A2")
      However, it does not work, probably due to the multiple quotation marks that confuse the script :C
      How do I avoid this problem?
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have a question about Excel, i have to create several charts one below the other dynamically.
      I have thought to use:
       
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count  
      And then to use it in this way:
      $Graph_position = "=Test1!A"&$iRowCount+2&":K"&$iRowCount+24 But it doesn't work with charts.
      Does anyone have a suggestion?
       
    • LoneWolf_2106
      By LoneWolf_2106
      Hi all,
      i have an empty csv file, i have a non formatted text file.
      What do i want to do?
      I want to automate the process "get external data" in Excel, i want to import the data from the text file and basically create a csv file with a specific character encoding.
      Is it possible with AutoIT?
       
    • breakbadsp
      By breakbadsp
      I  want to create a excel file from my script if it does not exist.
      _ExcelBookOpen throws error=2 if file does not exist, after this error i want to create new file at this point.
      can i use _FileCreate()?
      _Logger($sLogPath, "{INFO}------: Opening Excel File: " & $sExcelPath& "") While 1 Local $oExcelTestResult = _ExcelBookOpen($sExcelPath) If @error = 2 Then If not _FileCreate($sResExcelPath) Then MsgBox(0, "Error", "Error In Opening REsult Excel File: Error: " & String(@error)) _Logger($sLogPath, "{ERROR}------: Result Excel File does not exist.. tried to create new but :ERROR : " & String(@error) & "") ExitLoop Else _Logger($sLogPath, "{INFO}------: Result Excel File does not exist.. **Created New**: ") EndIf Else ExitLoop EndIf WEnd  
    • 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.