Extract unique values from columns

proficient

Well-known Member
Joined
Apr 10, 2012
Messages
745
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
Hi all,

Need your help, I have two columns, column A has

A B C O E W G H
whereas column B has
A B C E G H J L P

I want Unique alphabats from column B only, means as you can see O and W are also unique in column A but I want to extract J, L and P only.

TIA
 
Re: Want to extract unique values from columns

Aladin has given you a (somewhat complex) formula solution. If you are willing to entertain a VB solution, here is a subroutine that you would call from within a macro or event procedure. The subroutine takes three arguments... the first is the column of cells you want to check for unique letters (Column B from your example), the second is the columns of cells you want to compare is against (Column A from your example) and the third is the first cell that the output will start in.
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD][B][COLOR=#008000]' This is the subroutine that you call from your macro or event procedure[/COLOR][/B]
Sub UniqueToCol(CheckCol As Range, CompareCol As Range, OutCell As Range)
  Dim V As Variant, UCol As Variant, CCol As Variant
  UCol = Application.Transpose(CheckCol)
  CCol = CompareCol
  For Each V In CCol
    UCol = Filter(UCol, V, False)
  Next
  OutCell.Resize(1 + UBound(UCol)) = Application.Transpose(UCol)
End Sub


[B][COLOR=#008000]' A test macro to show how to call the above subroutine[/COLOR][/B]
Sub Test()
  UniqueToCol Range("B1:B9"), Range("A1:A8"), Range("C1")
End Sub[/TD]
[/TR]
</tbody>[/TABLE]

Thanks you so much rick, I'll definitely check the code as well, really appreciate your prompt response.
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Re: Want to extract unique values from columns

Not the way I interpreted the initial post, so the UDF in post#3 is not applicable.

Yes, your provided solution is not applicable at all, do you have other way to do this...? I am willing to know more way to do this. Thanks!
 
Upvote 0
Re: Want to extract unique values from columns

@Aladin Akyurek, You can't be wrong ever; I believe! Thanks a lot! this is exactly what I wanted.

Could you explain the formula for me?

Goal: Pick out the distinct items from the B range and display each one by one in the D range.

Formula: =IFERROR(INDEX($B$1:$B$9,SMALL(IF(FREQUENCY(IF(1-($B$1:$B$9=""),
IF(ISNA(MATCH($B$1:$B$9,$A$1:$A$9,0)),MATCH($B$1:$B$9,$B$1:$B$9,0))),
ROW($B$1:$B$9)-ROW($B$1)+1),ROW($B$1:$B$9)-ROW($B$1)+1),
ROWS($D$1:D1))),"")

Explanation:

IFERROR returns a blank (i.e., "") in case an error occurs in the INDEX bit.

INDEX returns a value from a position in the B range, corresponding to the integer value SMALL returns at each copy step, specified by ROWS. The ROWS bit deliver the number of rows in the range it is fed with.

The FREQUENCY bit...

The first IF bit

1-($B$1:$B$9="") eliminates empty/blank cells from consideration.

The second IF bit

ISNA(MATCH($B$1:$B$9,$A$1:$A$9,0))

eliminates B items which are not in the A range.

In the MATCH bit

MATCH($B$1:$B$9,$B$1:$B$9,0)

MATCH is matching a IF-filtered range against itself.
This evaluates to:

{FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;7;8;9}

for the sample we have. FALSE values would correspond to the empty/blank cells and B items which do occur in the A range.
Non-FALSE results read:
B7 matched against B1:B9 yields 7. That is, B7 matches B1:B9 at position (row) 7.
B8 at position/row 8.
B9 at row 9.

FREQUENCY(NumericValues,Bins)

yields a count per bin, that is, how many of the numeric values map onto a bin.

Example:

=FREQUENCY({2;0;5},{2,5})

yields an array result of {2;1;0}, saying bin 2 has two occurrences: 0 and 2, bin 5 one occurrence which is the number 5.

In our formula, NumericValues are:

IF(1-($B$1:$B$9=""),IF(ISNA(MATCH($B$1:$B$9,$A$1:$A$9,0)),MATCH($B$1:$B$9,$B$1:$B$9,0)))

Bins: ROW($B$1:$B$9)-ROW($B$1)+1)

The latter expression creates:

{1;2;3;4;5;6;7;8;9}

an integer vector (a set of consecutive bins).

The FREQUENCY bit yields in our case:

{0;0;0;0;0;0;1;1;1;0}

saying that J occurs once, L occurs once, etc.

The IF that envelops the foregoing FREQUENCY bit maps these frequencies to a copy of the integer vector

IF(FREQUENCY(IF(...,IF(...,MATCH($B$1:$B$9,$B$1:$B$9,0))),ROW($B$1:$B$9)-ROW($B$1)+1),
ROW($B$1:$B$9)-ROW($B$1)+1)

giving us the positions of distinct items in the A range: {FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;7;8;9;FALSE}

SMALL that is already mentioned picks out the relevant numbers one by one and feeds INDEX with that, enabling INDEX to fetch the items at those positions from the B range.

Hope this helps.
 
Upvote 0
Re: Want to extract unique values from columns

Thank you so much @Aladin
 
Upvote 0
Re: Want to extract unique values from columns

Hi Aladin,

I also have requirement very close to this example. presume that column A, has repeat of entries many times over. In this example only A is repeating twice. But in my case there are many entries that are repeating many times over.

In Column B i have date of sale against name in column A.

I want in another column, say D,

1. List on names (unique, without repetition) who were not present in Column A, before a date.
2. IN another column, say E, I want list of names form column A, that are not present after a date.

I need this to find out customer whom I have lost.

With regards,

Rizvi.M.H.
 
Upvote 0
Re: Want to extract unique values from columns

@ RIZVI

Would you post a small sample along with output that you need from that sample?
 
Upvote 0
Re: Want to extract unique values from columns

Dear Mr.Aladin Akyurek,

Thanks for the help. However I was able to figure out by myself by using the following formulas:


To obtain the list of customers from data base, I used this formula:

=IFERROR(INDEX(CustomerMaster,SMALL(IF(FREQUENCY(IF(CustomerMaster<>"",IF(CodeMaster=$BL$5,MATCH(CustomerMaster&"|"&CodeMaster,CustomerMaster&"|"&CodeMaster,0))),IvecMaster),IvecMaster),ROWS(HI$7:HI7))),"")

And then then to populate the list in Alphabetic order I used this formula in adjacent column:

=INDEX($HI$7:$HI$82, MATCH(LARGE(COUNTIF($HI$7:$HI$82, ">="&$HI$7:$HI$82), ROWS($HJ$7:HJ7)), COUNTIF($HI$7:$HI$82, ">="&$HI$7:$HI$82), 0))

Both above formulas were used by pressing control. shift and enter.

Then to obtain the date of Acquiring customer, I used this formula:

=IF(HJ7="","",VLOOKUP(HJ7,$C$7:$S$762,MATCH($H$6,$C$6:$AJ$6,0),0))

To Obtain last date of invoicing I used this formula in adjacent column:

=IF(TODAY()-IF(ISERROR(LOOKUP(2,1/(CustomerMaster=HJ7),InvDtMaster)),"",(LOOKUP(2,1/(CustomerMaster=HJ7),InvDtMaster)))>120,IF(ISERROR(LOOKUP(2,1/(CustomerMaster=HJ7),InvDtMaster)),"",(LOOKUP(2,1/(CustomerMaster=HJ7),InvDtMaster))),"")

And finally I used this formula to get Lost customer data:


=IF(HJ7="","",IF(TODAY()-IF(ISERROR(LOOKUP(2,1/(CustomerMaster=HJ7),InvDtMaster)),"",(LOOKUP(2,1/(CustomerMaster=HJ7),InvDtMaster)))>120,"Lost Customer","Regular Customer"))


However the computer has become slow and it take 2 to 3 minutes in processing.

Thank you once again and look forward to you to suggest improvements in above.


With warm regards,

Rizvi.M.H.
 
Upvote 0
Re: Want to extract unique values from columns

Hi,

I am using Excel 2007

RGDS,

Rizvi.M.H.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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