Forum Discussion

LeandroCampacci's avatar
LeandroCampacci
Copper Contributor
Mar 14, 2023
Solved

Excel: Script to remove duplicates on a table

Hello!   I have a script in an Excel table that organizes values ​​in descending order and removes duplicates from a table ("Table1"). When I recorded the scripts, or followed the steps manually, t...
  • SergeiBaklan's avatar
    Mar 14, 2023

    LeandroCampacci 

    Perhaps like

    function main(workbook: ExcelScript.Workbook) {
        let tabela1 = workbook.getTable("Tabela1");
        // Custom sort on table tabela1
        tabela1.getSort().apply([{ key: 1, ascending: false }], false);
        let selectedSheet = workbook.getActiveWorksheet();
        tabela1.getRange().removeDuplicates([0, 1, 3, 4], true);
        const rows = tabela1.getRowCount()
        for (let i = rows; i>0; i--)
            {
            if (tabela1.getColumn(1).getRange().getValues()[i][0] === '')
                tabela1.deleteRowsAt(i-1)
            }
    }

Resources