Jump to content

Recommended Posts

Posted

Hi,

I read some values from an excel sheet into a array,

but i don't need all the values in the array.

I want to delete some specific values from the array like W100, W101, M62, M68.

I searched the forum but i don't see the solution to my "little" problem.

Below the code i use to fill the array.

$row = $oExcel.Application.Selection.SpecialCells(11).row
Local $aArray1 = _ExcelReadArray($oExcel, 1, 4, $row, 1)

Thnx in advance

 

Posted

Maybe _ArrayDelete.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

For $i = $aArray1[0] to 1 step -1
    If $aArray1[$i] = "W100" or $aArray1[$i] = "W101" Or .... Then _ArrayDelete($aArray1, $i)
Next

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

@water

used your code, but there is no value deleted from the array?

Do i need to reasign the array?

Below a screenshot from the array.

array.jpg

Edited by drbyte
Posted

Can you show the actual code you run? The code I posted will return a syntax error.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

@water below the code i use.

I don't get the syntax error

$row = $oExcel.Application.Selection.SpecialCells(11).row ; find de latest row
    Local $aArray1 = _ExcelReadArray($oExcel, 1, 4, $row, 1) ;1 = Verticaal  0 = horizontaal
    If IsArray($aArray1) And UBound($aArray1, 0) > 0 Then ; Check if we retrieved any data
    _ArrayDisplay($aArray1, "Vertical")
    Else
        MsgBox(0, "Excel Data Test", "Error: Could not retrieve data from excell sheet")
    EndIf
    _ExcelBookClose($oExcel, 0, 0)
    WinClose("Database informatie ", "")

    For $i = $aArray1[0] To 1 Step -1
        If $aArray1[$i] = "W100" or $aArray1[$i] = "W101" Then _ArrayDelete($aArray1, $i)
    Next

    MsgBox(0, "Routing order" & "-" & $ordernummer, _ArrayToString($aArray1, @CRLF, 1, UBound($aArray1)))
  • Solution
Posted

I see. The problem is that element 0 doesn't contain the element count.

So my code needs to be changed to:

For $i = UBound($aArray1, 1) - 1 To 0 Step -1
    If $aArray1[$i] = "W100" or $aArray1[$i] = "W101" Then _ArrayDelete($aArray1, $i)
Next

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Glad to be of service :D

My UDFs and Tutorials:

  Reveal hidden contents

 

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