Jump to content

Help with delete row from array if value exist in cell


Go to solution Solved by Skeletor,

Recommended Posts

Hello

i need help and explanation with loop through 2 arrays 
here is my code and it works but without loop it just read only 30 lines from sn.txt and i use it line by line to delete rows that includes that values

all i need is find the cell with specific code that will be written in sn.txt and delete the entire row and loop it till the end of file
Thanks and appreciate the earlier help of yesterday 
2023-05-16_13-31-40.png.15c7b1ad64a05759ebb4d7a6b56bd33f.png

Local $oExcel =_Excel_Open()
    $datawb = _Excel_BookOpen($oExcel,@ScriptDir & "\agouzaold.xls")
    $datawb.worksheets("agouzaold").select
    $LastRow = $datawb.ActiveSheet.UsedRange.Rows.Count
    $mydata = _Excel_RangeRead($datawb, Default, Default )
    _ArrayColDelete($mydata, 0)
    _ArrayColDelete($mydata, 0)
    _ArrayColDelete($mydata, 1)
    _ArrayColDelete($mydata, 1)
    _ArrayColDelete($mydata, 1)
    _ArrayColDelete($mydata, 2)
    _ArrayColDelete($mydata, 3)
    _ArrayColDelete($mydata, 3)
    _ArrayColDelete($mydata, 3)
    _ArrayColDelete($mydata, 3)
    _ArrayColDelete($mydata, 3)
    _ArrayColDelete($mydata, 4)
    _ArrayColDelete($mydata, 4)
    _ArraySwap($mydata, 0, 2, True)
    _ArraySwap($mydata, 0, 1, True)
    _ArraySwap($mydata, 0, 3, True)
    _ArrayDelete($mydata, 0)
    _ArrayDelete($mydata, 0)
    _ArrayDelete($mydata, 0)
    _ArrayDelete($mydata, 0)
    _ArrayDelete($mydata, 0)
    _ArrayDelete($mydata, 0)
    _ArrayDelete($mydata, 0)
    _ArrayDelete($mydata, 0)
    _ArrayDelete($mydata, 0)
    _ArrayDelete($mydata, UBound($mydata) - 1)
    _ArrayDelete($mydata, UBound($mydata) - 1)
    _Excel_BookClose($datawb)
    ;--------------------------------   

For $i = UBound($mydata) - 1 To 1 Step -1
If Number($mydata[$i][3]) = 0 Then _ArrayDelete($mydata, $i)
Next

    ;--------------------------------
$filea = "sn.txt"
Global $filesn[30]
_FileReadToArray($filea, $filesn)   
    
For $i = UBound($mydata) - 1 To 1 Step -1
If Number($mydata[$i][0]) = $filesn[1] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[2] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[3] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[4] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[5] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[6] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[7] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[8] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[9] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[10] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[11] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[12] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[13] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[14] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[15] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[16] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[17] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[18] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[19] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[20] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[21] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[22] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[23] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[24] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[25] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[26] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[27] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[28] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[29] Then _ArrayDelete($mydata, $i)
If Number($mydata[$i][0]) = $filesn[30] Then _ArrayDelete($mydata, $i)  
Next

;--------------------------------
If IsArray($mydata) Then _ArrayDisplay($mydata)

 

Link to comment
Share on other sites

Basic example:

#include <Array.au3>
Local $mydata[11][4] = [[0],[1],[2],[3],[5],[6],[1],[2],[3],[5],[6]]
Local $filesn[] = [1,20,3]
_ArrayDisplay($mydata, "Before")
For $i = UBound($filesn) - 1 To 0 Step -1
    $aFindAll = _ArrayFindAll($mydata, $filesn[$i], 1, 0)
    If @error Then ContinueLoop
    For $j = UBound($aFindAll) - 1 To 0 Step - 1
        _ArrayDelete($mydata, $aFindAll[$j])
    Next
Next
_ArrayDisplay($mydata, "After")

 

Link to comment
Share on other sites

  • Solution

Replace :
 

$filea = "sn.txt"
Global $filesn[30]
_FileReadToArray($filea, $filesn)

With:

Local $filea = "sn.txt"
Local $filesn
_FileReadToArray($filea, $filesn)

For $i = 1 To UBound($filesn) - 1
    For $j = UBound($mydata) - 1 To 1 Step -1
        If Number($mydata[$j][0]) = $filesn[$i] Then
            _ArrayDelete($mydata, $j)
        EndIf
    Next
Next

Kind Regards
Skeletor

"Coffee: my defense against going postal."

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI

Link to comment
Share on other sites

17 hours ago, Skeletor said:

Replace :
 

$filea = "sn.txt"
Global $filesn[30]
_FileReadToArray($filea, $filesn)

With:

Local $filea = "sn.txt"
Local $filesn
_FileReadToArray($filea, $filesn)

For $i = 1 To UBound($filesn) - 1
    For $j = UBound($mydata) - 1 To 1 Step -1
        If Number($mydata[$j][0]) = $filesn[$i] Then
            _ArrayDelete($mydata, $j)
        EndIf
    Next
Next

Thank you so much
that's exactly what i needed 

Link to comment
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
 Share

×
×
  • Create New...