Extracting unique values from a list in multiple columns into a single column (using formula)

shakehands

New Member
Joined
Apr 25, 2014
Messages
2
hi guys,

first of all, many thanks for your help.
I've been searching for the answer to my problem, but I can't seem to find one anywhere, especially inside my head. So I thought, maybe the excel masters here can give me some solution !

So here is the trouble :
I have 5 columns of data, which is sometimes unique, and sometimes has duplicate value.
Here is the example :

On Column A (Listed from row 1 (A1) to row 5 (A5) > I have a,b,c,d,f
On Column B (Listed from row 1 (B1) to row 5 (B5) > I have c,d,a,f,g
On Column C (Listed from row 1 (C1) to row 5 (C5) > I have a,c,b,f,g
On Column D (Listed from row 1 (D1) to row 5 (D5) > I have d,g,b,c,a
On Column E (Listed from row 1 (E1) to row 5 (E5) > I have a,c,d,e,f

This is the illustration :

---A---B--C--D---E
1| A | C | A | D | A
2| B | D | C | G | C
3| C | A | B | B | D
4| D | F | F | C | E
5| F | G | G | A | F

----------------
All I want is to list the result on column F, and here is how the result should be :

---F
1| A
2| B
3| C
4| D
5| E
6| F
7| G

Note : It doesn't have to be alphabetically ordered.
As long as it lists each of all the items in the previous 5 columns, that is totally awesome !

Thanks a lot guys!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG25Apr17
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range("A1:E5")
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Not .Exists(Trim(Dn.Value)) [COLOR="Navy"]Then[/COLOR]
        .Item(Trim(Dn.Value)) = Empty
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
Range("F1").Resize(.Count) = Application.Transpose(.Keys)
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Upvote 0
Hey Guys, I have the same issue, but i have 8 columns from which i would like a single column of unique values.

This is the formula to build on:

=IFERROR(IFERROR(IFERROR(INDEX($A$2:$A$20, MATCH(0, COUNTIF($D$1:D1, $A$2:$A$20)+($A$2:$A$20=""), 0)), INDEX($B$2:$B$7, MATCH(0, COUNTIF($D$1:D1, $B$2:$B$7)+($B$2:$B$7=""), 0))), INDEX($C$2:$C$12, MATCH(0, COUNTIF($D$1:D1, $C$2:$C$12)+($C$2:$C$12=""), 0))), "")

 
Upvote 0
Hey Guys, I have the same issue, but i have 8 columns from which i would like a single column of unique values.

This is the formula to build on:

=IFERROR(IFERROR(IFERROR(INDEX($A$2:$A$20, MATCH(0, COUNTIF($D$1:D1, $A$2:$A$20)+($A$2:$A$20=""), 0)), INDEX($B$2:$B$7, MATCH(0, COUNTIF($D$1:D1, $B$2:$B$7)+($B$2:$B$7=""), 0))), INDEX($C$2:$C$12, MATCH(0, COUNTIF($D$1:D1, $C$2:$C$12)+($C$2:$C$12=""), 0))), "")


Add the following code to your work, using Alt + F11:

Function ArrayUnion(ParamArray Arg() As Variant) As Variant
' Code: Juan Pablo González
' Spec: Aladin Akyurek
' May 4, 2003
' Ref: TinyURL.com - shorten that long URL into a tiny URL
Dim TempUnion() As Variant
Dim i As Long, Itm As Variant, Ctr As Long
For i = LBound(Arg) To UBound(Arg)
Arg(i) = Arg(i)
If IsArray(Arg(i)) Then
For Each Itm In Arg(i)
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Itm
Next Itm
Else
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Arg(i)
End If
Next i
ArrayUnion = TempUnion
End Function

Given the following data on Sheet1 (otherwise, adjust to suit the sheet name)...

Row\Col
A​
B​
C​
D​
1​
13​
2​
jadjadqadRESULT
3​
kadxadjadjad
4​
jadladzadkad
5​
nadvadgadnad
6​
vadvadnadvad
7​
wadfaduadwad
8​
jadxadlad
9​
ladTADUAD
10​
UADVADtad
11​
tadnadxad
12​
xadfad
13​
tadqad
14​
kadzad
15​
tadgad
16​
uad
17​
JAD
18​
VAD
19​
vad
20​
xad

Define List using Insert | Name | Define (or Formulas | Name Manager) as referring to:
Rich (BB code):
=arrayunion(Sheet1!$A$2:$A$20,Sheet1!$B$2:$B$7,Sheet1!$C$2:$C$12)
Define Ivec as referring to:
Rich (BB code):
=ROW(INDIRECT("1:"&COLUMNS(List)))
In D1 control+shift+enter, not just enter:
Rich (BB code):
=SUM(IF(FREQUENCY(IF(1-(List=""),MATCH("~"&List,List&"",0)),Ivec),1))
In D3 control+shift+enter and copy down:
Rich (BB code):
=IF(ROWS($D$3:D3)<=$D$1,INDEX(List,SMALL(IF(FREQUENCY(IF(1-(List=""),
    MATCH(List,List,0)),Ivec),Ivec),ROWS(D$3:D3))),"")
 
Upvote 0
Add the following code to your work, using Alt + F11:

Function ArrayUnion(ParamArray Arg() As Variant) As Variant
' Code: Juan Pablo González
' Spec: Aladin Akyurek
' May 4, 2003
' Ref: TinyURL.com - shorten that long URL into a tiny URL
Dim TempUnion() As Variant
Dim i As Long, Itm As Variant, Ctr As Long
For i = LBound(Arg) To UBound(Arg)
Arg(i) = Arg(i)
If IsArray(Arg(i)) Then
For Each Itm In Arg(i)
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Itm
Next Itm
Else
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Arg(i)
End If
Next i
ArrayUnion = TempUnion
End Function

Given the following data on Sheet1 (otherwise, adjust to suit the sheet name)...

Row\Col
A​
B​
C​
D​
1​
13​
2​
jadjadqadRESULT
3​
kadxadjadjad
4​
jadladzadkad
5​
nadvadgadnad
6​
vadvadnadvad
7​
wadfaduadwad
8​
jadxadlad
9​
ladTADUAD
10​
UADVADtad
11​
tadnadxad
12​
xadfad
13​
tadqad
14​
kadzad
15​
tadgad
16​
uad
17​
JAD
18​
VAD
19​
vad
20​
xad

<tbody>
</tbody>


Define List using Insert | Name | Define (or Formulas | Name Manager) as referring to:
Rich (BB code):
=arrayunion(Sheet1!$A$2:$A$20,Sheet1!$B$2:$B$7,Sheet1!$C$2:$C$12)
Define Ivec as referring to:
Rich (BB code):
=ROW(INDIRECT("1:"&COLUMNS(List)))
In D1 control+shift+enter, not just enter:
Rich (BB code):
=SUM(IF(FREQUENCY(IF(1-(List=""),MATCH("~"&List,List&"",0)),Ivec),1))
In D3 control+shift+enter and copy down:
Rich (BB code):
=IF(ROWS($D$3:D3)<=$D$1,INDEX(List,SMALL(IF(FREQUENCY(IF(1-(List=""),
    MATCH(List,List,0)),Ivec),Ivec),ROWS(D$3:D3))),"")


Thank you for the response

I have been trying to make sense of this for the past 2 days.

So i defined list name and entered
=arrayunion(Sheet1!$A$2:$A$20,Sheet1!$B$2:$B$7,Sheet1!$C$2:$C$12)
where it says refers to in the dialog box.

Where do i define Ivec?

I have also included the code

Dim TempUnion() As Variant
Dim i As Long, Itm As Variant, Ctr As Long
For i = LBound(Arg) To UBound(Arg)
Arg(i) = Arg(i)
If IsArray(Arg(i)) Then
For Each Itm In Arg(i)
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Itm
Next Itm
Else
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Arg(i)
End If
Next i
ArrayUnion = TempUnion
End Function

in Alt F11.

Your assistance is appreciated
 
Upvote 0
Thank you for the response

I have been trying to make sense of this for the past 2 days.

So i defined list name and entered
=arrayunion(Sheet1!$A$2:$A$20,Sheet1!$B$2:$B$7,Sheet1!$C$2:$C$12)
where it says refers to in the dialog box.

Where do i define Ivec?

[...]

Also in the Name Manager... That's what "define" means.

Here is the workbook that implements the set up, the code for ARRAYUNION included: https://dl.dropboxusercontent.com/u...ns into a single column (using formula) .xlsm
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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