Formula to extract unique records only

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,501
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

ArticleQualityUnit
AA1Kgs
BB2Pair
DD3Dozen
EE4Grams
AA1Kgs
BB2Pair
AA1Kgs
AA1Kgs
DD3Dozen
AA3Pair
AA5Dozen
AA5Grams
AA1Kgs
AA1Kgs
AA1Kgs
AA1Kgs

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>


unique data required in columns H2:J17

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

ArticleQualityUnit
AA1Kgs
BB2Pair
DD3Dozen
EE4Grams
AA3Pair
AA5Dozen
AA5Grams

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>


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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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