AIisKing Posted December 14, 2020 Share Posted December 14, 2020 Hello, I want to loop through multiple excel files(dynamic) and delete rows that match the status "Inactive" in $obj_wb excel file(Static). However, the code does not work as intended. expandcollapse popup#include <File.au3> #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $g_iCounter = 0 Example() MsgBox("", "", "Total items deleted: " & $g_iCounter & ".") Func Example() Local $obj_Excel = _Excel_Open() Local $sPath = "Removed path" Local $obj_wb = _Excel_BookOpen($obj_Excel, $sPath) $obj_wb = _Excel_BookAttach($sPath) Local $obj_ws = $obj_wb.Worksheets("Sheet1") With $obj_ws Local $iLastRow = .Cells(.Rows.Count, "A").End(-4162).Row Local $aISIN = _Excel_RangeRead($obj_wb, $obj_ws, "A2:A" & $ilastrow) Local $aStatus = _Excel_RangeRead($obj_wb, $obj_ws, "B2:B" & $ilastrow) EndWith Local $sFileSelectFolder = "Removed path" $aFileList = _FileListToArray($sFileSelectFolder, "*.xls") If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf For $i = 1 To $aFileList[0] Local $iCounter = 0 $sFile = $sFileSelectFolder & "\" & $aFileList[$i] Local $obj_excel_files = _Excel_Open() Local $obj_file_wb = _Excel_BookOpen($obj_excel_files, $sFile) $obj_file_wb = _Excel_BookAttach($sFile) Local $obj_file_ws = $obj_file_wb.Worksheets("Sheet1") With $obj_file_ws Local $ilastrowFile = .Cells(.Rows.Count, "A").End(-4162).Row Local $aISINfile = _Excel_RangeRead($obj_file_wb, $obj_file_ws, "A2:A" & $ilastrowFile) EndWith For $iRowIndex = UBound($aISINfile)-1 To 1 Step -1 $k = _ArraySearch($aISIN, $aISINfile[$iRowIndex]) If $aStatus[$k] = "Inactive" Then $obj_file_wb.Activesheet.Range("A" &$iRowIndex+1).EntireRow.Delete $g_iCounter += 1 EndIf Next _Excel_BookClose($obj_wb_file, True) Next _Excel_BookClose($obj_wb, False) EndFunc Please advise why the script is not deleting the rows in the loop For $iRowIndex = UBound($aISINfile)-1 To 1 Step -1 BR, AIisKing Link to comment Share on other sites More sharing options...
Subz Posted December 14, 2020 Share Posted December 14, 2020 Use error checking, I'd look at the results of _ArraySearch, you may need to use partial for $iCompare. Link to comment Share on other sites More sharing options...
water Posted December 15, 2020 Share Posted December 15, 2020 Either use _Excel_BookOpen or _Excel_BookAttach Local $obj_wb = _Excel_BookOpen($obj_Excel, $sPath) $obj_wb = _Excel_BookAttach($sPath) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - 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