3 Ways to Extract unique values in Excel using VBA

Extract Unique Values In Excel
  • Save

Extract unique values in Excel is the most common data-crunching task in Excel. In this blog, we will learn multiple ways to Extract unique values in Excel.

Scenario :  

Suppose We have a list of customer names. The list has some duplicate values. We wish to extract unique values from it.

3 WAYS TO Extract Unique Values In Excel

A column contains 26 records. Data start from A2 and end with A27.

EXTRACT UNIQUE VALUES FROM A RANGE IN EXCEL
  • Save

Method to Extract Unique Values In Excel

1. Remove Duplicate

2. Advanced Filter

3. Index- Match Array Formula

4. Excel VBA

1. Remove Duplicate

“Remove Duplicates” option is the easiest way to extract unique values from a range.

Remove Duplicate
  • Save

Steps to apply to remove duplicates

Select the range where we want to remove duplicates>>Go to Data option in ribbon>>Click on Remove Duplicate>>Click On OK

Select the range
  • Save

Note-Remove duplicate removes the source data and contains only a unique list from the source data it means original data is removed.

2. Advance Filter :

Steps:-

1.Select the cell or range

2. Go to ribbon click on data tab>>in the sort and filter group click on Advanced

Select the cell or range
  • Save

Dialog box
  • Save

In the advance filter Dialog box, do the following.

If we want to copy the results of the filter to another location, do the following

  1. Click on Copy to another location.
  2. In the copy to box, enter the cell references eg. D1
  3. Select the unique records only

3. Index Match

For example Range A2:A27 contains duplicate values. We have applied the excel array formula in range D2 to extract unique records from the range.

=INDEX($A$2:$A$27,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$27),0))

The output is like below

Index Match
  • Save

3.1 IF BLANK VALUES IN A LIST

Suppose there are missing or blank values in our list from which you want to extract unique values. Then use the following formula.

=IFERROR(INDEX($A$2:$A$27, MATCH(0,IF(ISBLANK($A$2:$A$27),1,COUNTIF($F$1:F1, $A$2:$A$27)), 0)),””)

4.Using Excel VBA

The below code to the following

First, the code copies the data that contain duplicate value to the new location in sheet (H1)

Then remove the duplicates from the range H1

Using Excel VBA
  • Save

4.1 Using Advanced Filter

In this code, we have applied the advanced filter in range A1 and select unique records from them and paste them into the Range I1

Using Advanced Filter
  • Save

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Copy link
Powered by Social Snap