remove duplicate rows

Shweta

Active Member
hello,
how to delete duplicate rows from excel based on duplicate data in multiple columns.
example:

col1 col2 col3 col4
val1 val2 val3 val4
val1 val2 val3 val5
val5 val7 val8 val9

so as per above example, bot needs to look for the duplicates in col2 and col3 data only and in result, it should only return last row. as val2 and val3 are duplicates in first two.

thanks.
 
  • Like
Reactions: IoT

RavitejaKiran

New Member
Hi Shweta,

Try this code,


Dim excel, sheet, range As Object
Try
wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)
wb.Activate()
ws.Activate()
excel = ws.Application
sheet = excel.ActiveSheet
range = sheet.Range(Reference)
range.Select()
excel.Selection.RemoveDuplicates(Columns:=new Object() {FirstColumn,SecondColumn}, Header:=2)
Success = True
Catch e As Exception
Success = False
Message = e.Message
Finally
wb = Nothing
ws = Nothing
excel = Nothing
sheet = Nothing
range = Nothing
End Try

Inputs should be,
FirstColumn
SecondColumn
Reference
Workbook
Worksheet

Let me know if this helps
 

Shweta

Active Member
Thank you, I will try this.

If this column list is dynamic, for example, in one process I have to just two columns and next time there can be 3, 4 also. So how this can be set dynamic
 
Top