nooneclose Posted August 9, 2018 Posted August 9, 2018 (edited) How do I use variables to insert an empty cell/row into Excel using the Autoit function? _Excel_RangeInsert I know my code works if I use: _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "D4:D5", $xlShiftDown) However, I do not want just one change. I want the D4 and D5 to be variables so I can add many empty cells/rows wherever the columns do not match. I am using this to check two columns in excel and if they do not match I want to insert an empty cell/row at the index of column D Please help. For $Index = 2 To $IndexRows Step 1 Local $ExcelValue_C = _Excel_RangeRead($OpenWorkbook, Default, "C"&$Index) $Col_C_Array[$Array_Index] = $ExcelValue_C ;While the code loops every value in colum C is stored in the C array Local $ExcelValue_D = _Excel_RangeRead($OpenWorkbook, Default, "D"&$Index) $Col_D_Array[$Array_Index] = $ExcelValue_D ;While the code loops every value in colum D is stored in the D array if $Col_C_Array[$Array_Index] <> $Col_D_Array[$Array_Index] then ;Checks to see if the Value at index element in Array C and Array D are not the same _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "D4:D5", $xlShiftDown) ;Inserts a new row in column D. EndIf $Array_Index += 1 Next Edited November 1, 2018 by nooneclose
water Posted August 9, 2018 Posted August 9, 2018 You already use a variable in the _Excel_RangeRead statement. Use the same approach for _Excel_RangeInsert. nooneclose 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
nooneclose Posted August 9, 2018 Author Posted August 9, 2018 I Used _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "D"&$Index, $xlShiftDown) and it worked! I had the answer in front of me this whole time. Thank you very much, user: Water, you have no idea the headache you have saved me from. This may be a dumb question but can I use? _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "D"&$Index, "E"&$Index, $xlShiftDown) to insert an empty cell/row into columns D and E? Again thank you very much for helping me.
water Posted August 10, 2018 Posted August 10, 2018 You inserted an additional parameter ("E"&$Index). This doesn't work. Concatenate to one parameter like: _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "D" & $Index & ":E" & $Index, $xlShiftDown) nooneclose 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
nooneclose Posted August 10, 2018 Author Posted August 10, 2018 Thank you again! That's works so much better then what I did. I must say I am very new to Autoit but I love learning this language if you will. I also enjoy that the community is so willing to help one another,
water Posted August 10, 2018 Posted August 10, 2018 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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