How to Use Advanced Filter for Unique Records Only in Excel

We have a dataset that contains multiple identical entries. We want to remove identical entries and keep one of them.

Advanced Filter Unique Records Only


Use an Advanced Filter for Unique Records Only in Excel: 4 Ways

Method 1 – Excel Advanced Filter Feature to Filter Unique Records

We find 3 sets of identical records.

advanced filter dataset-Excel Advanced Filter Unique Records Only

Steps:

  • Select the entire range.
  • Go to the Data tab.
  • Select Advanced (from the Sort & Filter section).

advanced filter

The Advanced Filter window appears. In the window,

  • Under Action, mark the Copy to another location option.
  • The List range is automatically selected (i.e., B4:F17).
  • Select Copy to location (i.e., H4)
  • Tick the Unique Records Only option.
  • Click OK.

advanced filter window

This places the unique entries in the new location that you provided in the Advanced Filter window’s Copy to option.

advanced filter without criteria


Criteria to Use an Advanced Filter for Unique Records Only

We used criteria regarding Order Date, Product, and Quantity. We want records of products that have a certain amount (>50) of sold Quantity on a certain date (2/3/2022).

advanced filter criteria-Excel Advanced Filter Unique Records Only

  • Start the Advanced Filter.
  • Insert the same values as before.
  • Insert the condition range (i.e., G6:J7) in the Criteria range dialog box.
  • Click on OK.

advanced filter Criteria

⧬ Select the Criteria range including column headers.

The Advanced Filter brings records that meet the criteria as depicted in the below picture.

unique values satisfy criteria


Method 2 – The UNIQUE Function to Filter Unique Records Only

The UNIQUE function works only in Excel 365. The syntax of the UNIQUE function is:

=UNIQUE (array, [by_col], [exactly_once])

array; range or array from where you want the unique values extracted.

[by_col]; extract and compare type. FALSE conduct by Row and TRUE conduct by Column operation. [optional]

[exactly_once]; TRUE refers to a single occurrence value and FALSE refers to all unique values (default).[optional]

Steps:

  • Paste the following formula in any blank cell (i.e., H4).
=UNIQUE(B4:F17)

The UNIQUE function only takes the array (i.e., B4:F17) and returns all the uniques.

unique function-Excel Advanced Filter Unique Records Only

  • Hit Enter.

unique function result


Method 3 – Use the Remove Duplicates Feature to Remove Duplicates

Steps:

  • Select the range.
  • Go to the Data tab.
  • Select Remove Duplicates (from the Data Tools section).

remove duplicates-Excel Advanced Filter Unique Records Only

The Remove Duplicates window appears.

  • Click on the Select All option, then click on OK.

Remove duplicates window

A notification window appears saying Excel has removed the duplicates.

  • Click on OK.

NotificatIon window

This removes duplicates and keeps unique records only.

Final result


Method 4 – VBA Macro to Filter Unique Records

We have the dataset that contains duplicates. We will color format duplicate entries in order to identify them easily.

vba-Excel Advanced Filter Unique Records Only

Steps:

  • Press Alt + F11 to bring up the Microsoft Visual Basic window.
  • Select Insert (from the Toolbar) and click on Module.

Module insertion

  • Insert the following code in the Module.
Option Explicit
Sub Filter_Unique_Records()
Dim SourceRng As Range, PasteRng As Range
Dim lastRow As Long
Dim wrk As Worksheet
Set wrk = ThisWorkbook.Sheets("VBA")
Set PasteRng = wrk.Cells(4, 8)
If PasteRng <> vbNullString Then
lastRow = wrk.Columns(PasteRng.Column).Find("*", , , , xlByRows, xlPrevious).Row
wrk.Range(PasteRng, Cells(lastRow, PasteRng.Column + 2)).Delete xlUp
Set PasteRng = wrk.Cells(4, 8)
End If
lastRow = wrk.Columns(2).Find("*", , , , xlByRows, xlPrevious).Row
Set SourceRng = wrk.Range(Cells(4, 2), Cells(lastRow, 6))
SourceRng.AdvancedFilter Action:=xlFilterCopy, copytorange:=PasteRng, Unique:=True
End Sub

vba macro

The macro starts the source range from row 4 and column 2. The paste range starts from row 4 and column 8 using the VBA CELL function. The code will delete contents from the paste range using the VBA Range.Delete method. In the end, the macro executes VBA AdvancedFilter Action.

  • Use the F5 key to run the macro and return to the worksheet.

vba result


Download the Excel Workbook


<< Go Back to Advanced Filter | Filter in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Maruf Islam
Maruf Islam

MARUF ISLAM is an excellent marine engineer who loves working with Excel and diving into VBA programming. For him, programming is like a superhero tool that saves time when dealing with data, files, and the internet. His skills go beyond the basics, including ABACUS, AutoCAD, Rhinoceros, Maxsurf, and Hydromax. He got his B.Sc in Naval Architecture & Marine Engineering from BUET, and now he's switched gears, working as a content developer. In this role, he creates techy content... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo