How to Remove Duplicates from Excel XLSX Using C# .NET and VB.NET
Tags: webdev, devops, csharp, tutorial
Published: 2023-05-09 16:01:30

---
canonical_url: https://developer.mescius.com/blogs/how-to-remove-duplicates-from-excel-xlsx-using-c-sharp-net-and-vb-net
description: Learn how to remove duplicates from Excel XLSX using C# .NET and VB.NET. See more from Spread.NET today.
---
Removing duplicate data from Microsoft Excel files is one of the most underrated features! When an Excel file contains large amounts of data, there is a chance there are duplicate records which can be misleading when analyzing the data. Excel’s Remove Duplicate Rows feature allows users to pick which columns should be checked and remove duplicate data in the associated row.

In this blog, we are going to demonstrate how to remove duplicate rows in an Excel file programmatically in C# and VB.NET, how to invoke an Excel-like dialog during a .NET apps runtime to allow users to remove duplicate data in a familiar manner on the client side, and lastly, how developers can use that same Excel-like dialog within a code-free designer.

We will use [Spread.NET](https://developer.mescius.com/spreadnet), the world’s #1 selling .NET spreadsheet component, to accomplish this. Spread.NET delivers an Excel-like spreadsheet experience, with zero dependencies on Excel, to create enterprise spreadsheets, grids, dashboards, and forms with its comprehensive API.

**What we will cover:**

1.  [Remove Duplicate Rows in an Excel XLSX File Programmatically in C# and VB.NET](#remove-rows)
2.  [Invoke an Excel-like Dialog During a .NET Apps Runtime](#invoke)
3.  [Remove Duplicates with a Code-Free Designer](#remove-dupes)

### <a id="remove-rows"></a>Remove Duplicate Rows in an Excel XLSX File Programmatically in C# and VB.NET

Spread.NET for WinForms allows users to permanently delete duplicate data from a selected range programmatically using the [**RemoveDuplicates** method](https://developer.mescius.com/spreadnet/docs/latest/online-win/GrapeCity.Spreadsheet~GrapeCity.Spreadsheet.SpreadsheetHelper~GetRemoveDuplicatesRange.html) from the [**IRange** interface](https://developer.mescius.com/spreadnet/docs/latest/online-win/GrapeCity.Spreadsheet~GrapeCity.Spreadsheet.IRange~RemoveDuplicates.html) and specifying the target range. In the example below, we will remove duplicate data programmatically from a list of contacts within an Excel .XLSX file.

C#:

```
    int[] columns = { 1, 2 };
    fpSpread1.AsWorkbook().ActiveSheet.Range("A3:G28").RemoveDuplicates(columns, YesNoGuess.No);
```

VB.NET:

```
    Dim columns As Integer() = {1, 2}
    fpSpread1.AsWorkbook().ActiveSheet.Range("A3:G28").RemoveDuplicates(columns, YesNoGuess.No)
```

Results from the above code:

![Remove Duplicates Excel/XLSX C#](https://files.grapecity.com/gc-website-media/hrbhiav2/01-remove.png?width=500&height=277.77777777777777)

Spread.NET users can also invoke an Excel-like [**UNIQUE** formula function](https://developer.mescius.com/spreadnet/docs/latest/online-formula/functionUnique.html) to return a list of all the unique values in a cell range; this option does not delete the duplicates. An end-user can apply this formula or programmatically by setting the formula to a cell. [You can learn how to use _Formulas in Cells_ with Spread.NET here in our documentation](https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-cell-formula.html).

C#:

```
    IWorkbook workbook = fpSpread1.AsWorkbook();
    workbook.WorkbookSet.CalculationEngine.CalcFeatures = CalcFeatures.All;
    fpSpread1.Sheets[1].Cells[2, 4].Formula = "UNIQUE(A3:B28)";
```

VB.NET:

```
    Dim workbook As IWorkbook = fpSpread1.AsWorkbook()
    workbook.WorkbookSet.CalculationEngine.CalcFeatures = CalcFeatures.All
    fpSpread1.Sheets(1).Cells(2, 4).Formula = "UNIQUE(A3:B28)"
```

### ![Remove Duplicates Excel/XLSX C#](https://files.grapecity.com/gc-website-media/v2wbg3wo/02-remove.gif?width=500&height=471.1673699015471)

### <a id="invoke"></a>Invoke an Excel-like Dialog During a .NET Apps Runtime

[New with the v16 release](https://developer.mescius.com/blogs/spreadnet-v16-is-released#remove), Spread.NET now offers a powerful built-in Excel-like [**Remove Duplicates** dialog](https://developer.mescius.com/spreadnet/docs/latest/online-win/work-with-builtin-dialog.html#i-heading-remove-duplicates-dialog). This runtime dialog can be invoked programmatically, allowing the user to remove duplicate values from a range of values with an interactive UI during a .NET app’s runtime.

C#:

```
    activeSheet.Cells["A1:E7"].Select();
    FarPoint.Win.Spread.Dialogs.BuiltInDialogs.RemoveDuplicates(fpSpread1).ShowDialog(fpSpread1);
```

VB.NET:

```
    activeSheet.Cells("A1:E7").Select()
    FarPoint.Win.Spread.Dialogs.BuiltInDialogs.RemoveDuplicates(fpSpread1).ShowDialog(fpSpread1)
```

### ![Remove Duplicates Excel/XLSX C#](https://files.grapecity.com/gc-website-media/crpcflql/03-remove.png?width=462&height=315)

### <a id="remove-dupes"></a>Remove Duplicates with a Code-Free Designer

Spread.NET offers a [Designer](https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-designerguide.html) that allows developers to visually design a Spread component using a graphical Excel-like user interface. It also supports being deployed during runtime to allow users to modify spreadsheets in their application. The Spread Designer has many [advanced features](https://developer.mescius.com/spreadnet/docs/latest/online-win/spwin-spd-oview.html) with a familiar Excel-like look and feel. This Designer saves developers time by removing the need to programmatically create and/or modify the Spread component.

Spread Designer provides a **Remove Duplicates** ribbon button under the **Data Tools** group of the **Data** tab.

![Remove Duplicates Excel/XLSX C#](https://files.grapecity.com/gc-website-media/llwhpozw/04-remove.png?width=500&height=97.74436090225564)

Head to the [original blog](https://developer.mescius.com/blogs/how-to-remove-duplicates-from-excel-xlsx-using-c-sharp-net-and-vb-net) to see the changes applied in the Spread Designer using the Remove Duplicates dialog.

### GrapeCity Spreadsheet Components

This article does not even scratch the surface of the full capabilities of the [**GrapeCity Spread.NET**](https://developer.mescius.com/spreadnet) spreadsheet component. Review the [documentation](https://developer.mescius.com/spreadnet/docs/) to see the many available features and [download the demo explorer](https://developer.mescius.com/spreadnet/demos) to see the features in action and interact with the sample code.

Integrating a spreadsheet component into your applications allows you to customize your users' experience and provide them with familiar spreadsheet functionality without referring them to an external program. To learn more about Spread.NET and the new features added with the v16 release, check out our [release blog](https://developer.mescius.com/blogs/spreadnet-v16-is-released).