dersiniar 1 Posted April 25 Share Posted April 25 Hi i want to add array to to excel file that has data allready in. I want to add to end to data that is allready there. Example if existing data endas A:45 then i want array to go A46 But func i have still dont do this. It still populates A:1 cell Func _ExportData($aArray) Sleep(100) Global $oExcel = _Excel_Open(False, False, True, True, True) Global $oWorkBook If Not FileExists($sDataFilePath) Then $oWorkBook = _Excel_BookNew($oExcel) Else $oWorkBook = _Excel_BookOpen($oExcel, $sDataFilePath) ;ConsoleWrite($sDataFilePath & @CRLF) ;ConsoleWrite($oWorkBook & @CRLF) EndIf $lastline=_Excel_RangeRead ($oWorkbook,Default,Default,Default) _Excel_RangeWrite($oWorkBook, $lastline, $aArray) If FileExists($sDataFilePath) Then _Excel_BookSaveAs($oWorkBook, $sDataFilePath) Else _Excel_BookSaveAs($oWorkBook, $sDataFilePath) EndIf _Excel_Close($oExcel, Default, True) Sleep(1000) killEXCEL() EndFunc ;==>_ExportData Link to post Share on other sites
Solution junkew 469 Posted April 25 Solution Share Posted April 25 Why do you think $lastline has the lastline? did you check that value with a consolewrite/msgbox You probably need something like $LastRow = $oWorkbook.ActiveSheet.Range("A1").SpecialCells($xlCellTypeLastCell).Row FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to post Share on other sites
dersiniar 1 Posted April 25 Author Share Posted April 25 12 minutes ago, junkew said: Why do you think $lastline has the lastline? did you check that value with a consolewrite/msgbox You probably need something like $LastRow = $oWorkbook.ActiveSheet.Range("A1").SpecialCells($xlCellTypeLastCell).Row Hmm, now it didn't overwrite data. That's good, but, it didn't add array at all now lol $LastRow = $oWorkbook.ActiveSheet.Range("A1").SpecialCells($xlCellTypeLastCell).Row Consolewrite($LastRow & @crlf) _Excel_RangeWrite($oWorkbook.Activesheet, $LastRow, $aArray) Link to post Share on other sites
water 2,642 Posted April 25 Share Posted April 25 Please have a look at the wiki: https://www.autoitscript.com/wiki/Excel_Range about the last used cell. Please check the value of @error after calling _Excel_RangeWrite. 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 (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to post Share on other sites
dersiniar 1 Posted April 25 Author Share Posted April 25 This is what I tried, but still no luck $LastRow = $oWorkbook.ActiveSheet.Range("A1").SpecialCells($xlCellTypeLastCell).Row $Rowrange = "A"&$LastRow+1 Consolewrite($Rowrange & @crlf) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray, $Rowrange) Link to post Share on other sites
dersiniar 1 Posted April 25 Author Share Posted April 25 1 hour ago, dersiniar said: This is what I tried, but still no luck $LastRow = $oWorkbook.ActiveSheet.Range("A1").SpecialCells($xlCellTypeLastCell).Row $Rowrange = "A"&$LastRow+1 Consolewrite($Rowrange & @crlf) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray, $Rowrange) It worked like a charm... I had excel opened in task manager.. So it was not able to save it junkew 1 Link to post Share on other sites
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