How to remove duplicate values

Hi, here I’m attaching a sample excel, Having headers as name, phone no and address, the main intention is to remove duplicate rows and right in to sheet 2,but address is different, then how can i proceed this.
Test.xlsx (8.9 KB)

@Chippy_Kolot
Could you Provide the required output

Hi @Chippy_Kolot

Try this

DT1.AsEnumerable() _
    .GroupBy(Function(row) New With { _
        Key .Name = row.Field(Of String)("Name"), _
        Key .Phno = row.Field(Of Double)("Phno") _
    }) _
    .Select(Function(Group) Group.First()) _
    .CopyToDataTable()

Test (6).xlsx (9.2 KB)

Regards,

1 Like

Hi @Chippy_Kolot

→ Read Range Workbook
Output-> dt

→ Use the below syntax in Assign:

dt2 = (From row In dt1.AsEnumerable()
       Group row By key = New With {
           .Name = row.Field(Of String)("Name"),
           .Phno = row.Field(Of String)("Phno")
       } Into Group
       Select Group.First()).CopyToDataTable()

dt2 is of DataType System.Data.DataTable

→ Write Range Workbook dt2
Test.xlsx (9.3 KB)

Since the Address are different no rows will be removed from the Sheet1.

Hope it helps!!

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