I have a scenario that I need to check if there are duplicate records in one column then put comment in other column. Would anyone here please help me? Thanks everyone!!
Data
Name | Comment
James
James
James
Paul
Ryan
Output
Name | Comment
James | duplicate
James | duplicate
James | duplicate
Paul
Ryan
@James_Callos
Excel Application Scope
__Read Range → save data to an datatable variable (eg. dtData)
__For each row in dtData
____intIndex = dtData.Rows.IndexOf(row)
____For each row2 in dtData
______intIndex2 = dtData.Rows.IndexOf(row2)
______If row(“Name”) = rows(“Name”) and intIndex <> intIndex2
________row(“Comment”) = “duplicate”
________Break;
__Write Range → write dtData back to Excel
Hello @GouthamVijay Thanks for this! It really helps, however, this is the real data that i’m expecting. Would you please help again? Sorry for the confusion. So Item ‘111’ should be the only item to be check if it has multiple items if the Name - Age - Company are the same (group). Thank you
If i’m not wrong with the understanding, Item 111 should be the only item needed to check for duplicates, why not for other item do you have any restrictions?
If that so then you can apply the following logic,
in the place of
row(“Name”).ToString=val(“Name”).ToString
you can replace to
(row(“Name”).ToString=val(“Name”).ToString) AND row(“Name”).ToString=“111” AND val(“Name”).ToString=“111”
Hello @GouthamVijay apologies for the confusion. What I was saying is if the records have duplicates filtered by Name, Age, and Company then the Bot will check if the item contains item 111, if it does, check if it has other item account then comment exception multiple item codes. If it is only item 111, comment multiple 111 item codes. Sorry for the confusion again
Hello @GouthamVijay apologies on the late reply. I was sick. I checked your codes and it is checking if it found duplicate, my concern is for example…
so the condition or logic should be if Name, Age, and Surname are the same and has duplicates, it will check the Item column if it only has Item 111 or if it has multiple item 111, if yes, comment duplicate, if not, okay or proceed.
Sorry for the late response,
ok i understood, we should ignore other than 111 item for commenting Duplicate. Then how item 123 has been commented duplicate in the above example.
Hi you could use this code for easier reference
– Use a for each row in data table activity
– Inside that use an assign activity to get current row value from “Name”
eg. Name = Row(“Name”).ToString
– Then use an if else activity to check if there are duplicates within the column
You might want to use this LINQ function:
(From x In (dtYourTable.defaultview.totable(False, “Name”)).asenumerable() Where x(“Name”).Equals(Name) Select x).ToArray.Length > 1
– Inside of that if activity put an activity for writing comment in the next cell
Note: use counter to know if what cell should you write the value for the comment