How to remove duplicate andalso delete this row

Hello all!

I have a excel like this below:

This table has to be

How is it possible? Can anyone help me ?


  1. read data into datatable dt
  2. Use assign with dt = dt.AsEnumerable.GroupBy(function(x) x("Number").ToString+x("Name").ToString).Where(function(x) x.Count=1).Select(function(x) x.First()).CopyToDataTable
    3.Write the data back to excel or new excel


1 Like

Hi @Betul_Dundar ,

creates a new DataTable (uniqueRows ) with these filtered rows.

InputDataTable: Your Input DT

Assign: uniqueRows=

(From row In inputDataTable.AsEnumerable()Group By key = New With { Key .Value = row("ColumnA"), Key .Value2 = row("ColumnB")} Into Group Where Group.Count() = 1 Select Group(0)).CopyToDataTable()

Vinit Mhatre

Hi @Betul_Dundar

You can simply use this query

distinctRows = (From row In inputDataTable.AsEnumerable()
                   Group row By number = row.Field(Of Integer)("Number") Into groupedRows
                   Select groupedRows.First()).CopyToDataTable()


you can try this as well

dt1.AsEnumerable.GroupBy(Function(a) Tuple.Create(a(0).ToString,a(1).ToString)).Where(Function(b) b.Count=1).SelectMany(Function(grp) grp).copytodatatable

Hi @Betul_Dundar

Use below expression:

DT2.AsEnumerable().GroupBy(Function(row) New With { Key .Number = Int32.Parse(row.Field(Of String)(“A”)), Key .Name = row.Field(Of String)(“B”) }).Where(Function(Group) Group.Count().Equals(1)).SelectMany(Function(Group) Group).CopyToDataTable()


** Replace “A” & “B” with your Column Name or Column Index - Number & Name OR 0 & 1

Hope it will helps you :slight_smile:

1 Like

Thank you it worked! :star_struck:

1 Like

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