Moonscarlet Posted December 20, 2017 Posted December 20, 2017 Hello, I am trying to remove duplicates from two columns but I haven't been able to do it properly in my script. I tried using ".RemoveDuplicates()", but if I put: $Workbook.Sheets(1).Range("A1:B50").RemoveDuplicates(1) or $Workbook.Sheets(1).Range("A1:B50").RemoveDuplicates(2) This won't give me the correct results as I want to remove the duplicates if both columns are found again, after recording the macro that's what I get in VBA: ActiveSheet.Range("$A$1:$B$50").RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes But I don't know how to put that "Array(1, 2)" without getting errors. Appreciate your help.
water Posted December 20, 2017 Posted December 20, 2017 Global $aColumns = [1, 2] $Workbook.Sheets(1).Range("A1:B50").RemoveDuplicates($aColumns) 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
Moonscarlet Posted December 20, 2017 Author Posted December 20, 2017 13 minutes ago, water said: Global $aColumns = [1, 2] $Workbook.Sheets(1).Range("A1:B50").RemoveDuplicates($aColumns) Thanks but this also gave me an error: "The requested action with this object has failed."
water Posted December 20, 2017 Posted December 20, 2017 Could you please add a COM error handler (please check the help file for ObjEvent) so we get more detailed error information? 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
Moonscarlet Posted December 20, 2017 Author Posted December 20, 2017 2 hours ago, water said: Could you please add a COM error handler (please check the help file for ObjEvent) so we get more detailed error information? You mean like this? "COM Error intercepted ! err.number is: 0x80020009 err.windescription: Exception occurred. err.description is: err.source is: err.helpfile is: err.helpcontext is: 0 err.lastdllerror is: 0 err.scriptline is: 701 err.retcode is: 0x80070057"
water Posted December 20, 2017 Posted December 20, 2017 Correct. Unfortunately the returned information is not very helpful I will do some testing the next few days and hope to come back with a solution. 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
Moonscarlet Posted December 20, 2017 Author Posted December 20, 2017 1 minute ago, water said: Correct. Unfortunately the returned information is not very helpful I will do some testing the next few days and hope to come back with a solution. Much Appreciated
water Posted December 22, 2017 Posted December 22, 2017 This works great with Excel 2016: #include <Excel.au3> Global $aData[][] = [[1,2],[1,2],[2,3],[2,3]] Global $aColumns = [1, 2] Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookNew($oExcel) _Excel_RangeWrite($oWorkbook, 1, $aData) $oWorkbook.Sheets(1).Range("A1:B50").RemoveDuplicates($aColumns) 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
Moonscarlet Posted December 22, 2017 Author Posted December 22, 2017 26 minutes ago, water said: This works great with Excel 2016: #include <Excel.au3> Global $aData[][] = [[1,2],[1,2],[2,3],[2,3]] Global $aColumns = [1, 2] Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookNew($oExcel) _Excel_RangeWrite($oWorkbook, 1, $aData) $oWorkbook.Sheets(1).Range("A1:B50").RemoveDuplicates($aColumns) This is weird, it does work, even though it's the same as what you told me to use the other day! I don't know why I kept getting that error then. Thanks a lot for helping me get this to work.
water Posted December 22, 2017 Posted December 22, 2017 Did you name your workbook variable $oWorkbook or $Workbook? 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
Bert Posted December 22, 2017 Posted December 22, 2017 I just discovered something on my work laptop called "Spreadsheet Compare". The Vollatran project My blog: http://www.vollysinterestingshit.com/
Moonscarlet Posted December 22, 2017 Author Posted December 22, 2017 (edited) 11 minutes ago, water said: Did you name your workbook variable $oWorkbook or $Workbook? It's something else as I have the sheet saved as a variable altogether Global $oExcel = _Excel_Open() Global $Prepare= _Excel_BookOpen($oExcel,@ScriptDir&"\Prepare.xlsx",True) Global $ProgressSheet= $Prepare.Sheets(2) Then after a bit of code that fills some columns from another excel sheet: Global $aColumns = [1, 2] $ProgressSheet.Range("S1:T"&$LastCell).RemoveDuplicates($aColumns) Maybe I messed up the last line by adding another .Sheets(2) by mistake or something , that's the only thing that I can think of that could've happened, I don't remember. Edited December 22, 2017 by Moonscarlet
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