Excel Automation.Delete Duplicate Rows
- To be able to run this example you need to install UiPath.Excel.Activities. See more details on how to install packages here.
This sample sorts the values from an Excel sheet from the smallest to largest and then deletes duplicate rows.
Steps to automate
- Open Excel application
- Open "Sort" window
- Select sort options
- Save Excel file
- Remove duplicates from Excel
- Close Excel file
- Open Excel window using "Start Application" activity.
- All the data in the Excel sheet will be sorted using UiPath activity called "Send hotkey": Ctrl+a, Alt+d and then press s.
- In Sort window click "Column A", click "Smallest to Largest" and then click "OK".
- Click save the Excel file because all the data from Excel will be loaded in a data table.
- Take everything from Sheet1 into DataTable using "Read Cell Range" activity.
- Use a "While" activity and a "rowIndex" variable to move forward in the data table rows. Compare the value of each row with the value of the next row. If the values are equal remove "rowNext", otherwise increment the row index with one.
- With "Write Cell Range" activity, save the resulted data table in Sheet2.
- Close the Excel window.
Read more about Excel Automation.