Formula to extract unique records only

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,516
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I need a formula to extract only the first occurrence of the data or unique records I can say. The formula should
look all the 3 columns in a row and should treat it as a duplicate if all the 3 cells are equal - otherwise not.

here is a sample data in A2:C17

[TABLE="width: 192"]
<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]Article[/TD]
[TD="class: xl65, width: 64"]Quality[/TD]
[TD="class: xl65, width: 64"]Unit[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl66"]Kgs[/TD]
[/TR]
[TR]
[TD="class: xl66"]BB[/TD]
[TD="class: xl66"]2[/TD]
[TD="class: xl66"]Pair[/TD]
[/TR]
[TR]
[TD="class: xl66"]DD[/TD]
[TD="class: xl66"]3[/TD]
[TD="class: xl66"]Dozen[/TD]
[/TR]
[TR]
[TD="class: xl66"]EE[/TD]
[TD="class: xl66"]4[/TD]
[TD="class: xl66"]Grams[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl66"]Kgs[/TD]
[/TR]
[TR]
[TD="class: xl66"]BB[/TD]
[TD="class: xl66"]2[/TD]
[TD="class: xl66"]Pair[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl66"]Kgs[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl66"]Kgs[/TD]
[/TR]
[TR]
[TD="class: xl66"]DD[/TD]
[TD="class: xl66"]3[/TD]
[TD="class: xl66"]Dozen[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]3[/TD]
[TD="class: xl66"]Pair[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]5[/TD]
[TD="class: xl66"]Dozen[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]5[/TD]
[TD="class: xl66"]Grams[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl66"]Kgs[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl66"]Kgs[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl66"]Kgs[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl66"]Kgs[/TD]
[/TR]
</tbody>[/TABLE]


unique data required in columns H2:J17

in the above case the answer in H2:J17 would be

[TABLE="width: 192"]
<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]Article[/TD]
[TD="class: xl65, width: 64"]Quality[/TD]
[TD="class: xl65, width: 64"]Unit[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl66"]Kgs[/TD]
[/TR]
[TR]
[TD="class: xl66"]BB[/TD]
[TD="class: xl66"]2[/TD]
[TD="class: xl66"]Pair[/TD]
[/TR]
[TR]
[TD="class: xl66"]DD[/TD]
[TD="class: xl66"]3[/TD]
[TD="class: xl66"]Dozen[/TD]
[/TR]
[TR]
[TD="class: xl66"]EE[/TD]
[TD="class: xl66"]4[/TD]
[TD="class: xl66"]Grams[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]3[/TD]
[TD="class: xl66"]Pair[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]5[/TD]
[TD="class: xl66"]Dozen[/TD]
[/TR]
[TR]
[TD="class: xl66"]AA[/TD]
[TD="class: xl66"]5[/TD]
[TD="class: xl66"]Grams[/TD]
[/TR]
</tbody>[/TABLE]


Rest all rows till 17 will show blanks as there is no more unique data.

If any one can provide a solution

Regards,

Humayun
 
The macro will do it automatically, no need to adap 17, 600 or any number later on.
Code:
[LEFT][COLOR=#222222][FONT=Verdana]Public Sub UniqueRow()
'LastRow
Dim lr As Long
lr = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Range("A1:C" & lr).Copy
Range("h1").Select
ActiveSheet.Paste
Selection.RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]End Sub[/FONT][/COLOR][/LEFT]

or if you want it done automatically when you come on sheet, right click sheet name, click view code and paste
Code:
Private Sub Worksheet_Activate()
'LastRow
Dim lr As Long
lr = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Range("A1:C" & lr).Copy
Range("h1").Select
ActiveSheet.Paste
Selection.RemoveDuplicates Columns:=Array(1, 2, 3), _
        Header:=xlYes
End Sub
When you add data, simply leave the sheet and come back
 
Last edited:
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi James,

Thanks for the code

Hello,

You can test following:

Code:
Sub Unique3Cols()
With Worksheets("Sheet1")
.Range("A1:C17").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Range("H1:J1"), Unique:=True
End With
End Sub

HTH

What if the range A:C is not in a sequence.... i mean the columns are A,B & D... Is it possible ??
 
Upvote 0
You can test :

Code:
Sub Unique3Cols()
    With Worksheets("Sheet1")
        .Range("H1:K1").Value = .Range("A1:D1").Value
        .Range("A1:D17").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Range("H1:K1"), Unique:=True
        .Columns("J:J").Delete Shift:=xlToLeft
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top