Click to See Complete Forum and Search --> : Remove Duplicates in Excel


lozan
June 7th, 2008, 01:58 AM
Hi. I've been trying to remove duplicates in Excel worksheet.
So far, i've been trying to get something out of:

Microsoft.Office.Interop.Excel.Range.RemoveDuplicates(object Columns, Microsoft.Office.Interop.Excel.XlYesNoGuess Header)

which doesn't seem to have any explanation in MSDN nor anywhere i looked for. Well, it's pretty self-explanatory really, except the 1st parameter. I tried passing it an int array and casting it to object, but i am getting an exception. I can pass an int, like (object)1 for example, but then it takes in account just the 1st column and will remove all duplicates according to that.
So for example, if i input this table:
12 123 456
ds fds
12 123 456
12 123 456
54 123 33
54 47 33

this is what i am getting:

12 123 456
ds fds
54 123 33

And that's not i want to get. My last row should have stayed as well.
That would be like an equivalent to the Excel function when we press "Remove duplicates" and have an option to select which columns should be taken into account.

Thanks

lozan
June 7th, 2008, 02:34 AM
I solved it. I just passed an int array casted to object.

bebef_1987
June 10th, 2010, 08:43 AM
can you explain how do you make the conection an remove the duplicates in more details pls

foamy
June 10th, 2010, 08:50 AM
This thread i two years old! Please make a new thread if you need help.

To answer the question: You can modify an Excel workbook using C# in a few ways, such as through COM Interop (http://msdn.microsoft.com/en-us/library/ms173186(VS.80).aspx) or an OLEDB Adapter (http://www.codeproject.com/KB/office/excel_using_oledb.aspx).