Impossible to delete duplicate rows in specified range


I have been trying to delete duplicated rows from an excel dataTable but when I use ‘Delete duplicate rows’ or ‘Remove duplicate range’ it doesn’t work. I have also tried deleting rows by single column using this code : dt.AsEnumerable().GroupBy(Function(a) a.Field(Of String)(“reference”)).Select(Function(b) b.First).CopyToDataTable()

Nothing works … I either get an error specifiying that I cannot delete the specified range, or no error but no changes in my excel file.

Could someone please help me solve this issue.
Thank you !

Try this code…just update the column and datatable names. Use in an assign activity on the datatable:

(From p in dt.Select() where( From q in dt.Select() where q(“ColumnName”).Equals(p(“ColumnName”)) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()

1 Like

It still doesn’t work.
No error this time, but it doesn’t remove duplicates from excel.
I did :
-Read Range (output parameter : dt)
-Assign dtRemoveDuplicates = (From p in dt.Select() where( From q in dt.Select() where q(“Référence”).Equals(p(“Référence”)) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()
-Write range dtRemoveDuplicates

The column name is Référence and it is a combination of letters and numbers following this example : ABC-1234 which is saved as a generic value

Apologies, I was using the wrong code. Try this:

((From LineNo In dt.DefaultView.ToTable(True,“Référence”).Select().ToList() Select (From row In dt.Select Where row(“Référence”).ToString=LineNo(“Référence”).ToString Select row).ToList(0)).ToList()).CopyToDatatable()

Thank you ! It worked :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.