Join Only Unique Values separate By Vertical Bar

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Hello,

I have B:F 5 columns in which there are unique 5 values or may max 2 or 3 duplicate values I want to Join Only Unique Values separate By Vertical Bar in the Column H as shown below

For a more detail the image is attached. Pease suggest formula or VBA

*ABCDEFGHI
1
2
3
4Join Only Unique Values
5n1n2n3n4n5Separate By Vertical Bar
6881821218 | 18 | 21
72202025252 | 20 | 25
82101013132 | 10 | 13
9351123253 | 5 | 11 | 23 | 25
10121116201 | 2 | 11 | 16 | 20
118151920258 | 15 | 19 | 20 | 25
12361821223 | 6 | 18 | 21 | 22
131445241 | 4 | 5 | 24
142121214172 | 12 | 14 | 17
151121420221 | 12 | 14 | 20 | 22
162111517182 | 11 | 15 | 17 | 18
1713610221 | 3 | 6 | 10 | 22
18551019255 | 10 | 19 | 25
1935514183 | 5 | 14 | 18
20181821232518 | 21 | 23 | 25
21131315252513 | 15 | 25
227121221217 | 12 | 21
23161111151 | 6 | 11 | 15
24561010125 | 6 | 10 | 12
25131819192113 | 18 | 19 | 21
26261214182 | 6 | 12 | 14 | 18
2712510121 | 2 | 5 | 10 | 12
2822722252 | 7 | 22 | 25
29362424253 | 6 | 24 | 25
30451416174 | 5 | 14 | 16 | 17
31381218223 | 8 | 12 | 18 | 22
3210142122252 | 12 | 14 | 14 | 14
332141522222 | 14 | 15 | 22
34131321222413 | 21 | 22 | 24
35691616206 | 9 | 16 | 20
36
37

Thank you all.

I am using Excel 2000

Regards,
Moti
 

Attachments

  • Join Only Unique Values.png
    Join Only Unique Values.png
    39.8 KB · Views: 6

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try the following in cell H6 & copy down.

Excel Formula:
=TEXTJOIN("|",TRUE,UNIQUE(B6:F6,TRUE))
 
Upvote 0
Try the following in cell H6 & copy down.

Excel Formula:
=TEXTJOIN("|",TRUE,UNIQUE(B6:F6,TRUE))
kevin9999, it gives me result #NAME? I guess may be the formula is not computable with my Xl2000 version

Thank you for your help

God Luck

Kind Regards
Moti
 
Upvote 0
Sorry, I didn't notice your version of Excel is 2003 or older. That's why it didn't work.
 
Upvote 0
Sorry, I didn't notice your version of Excel is 2003 or older. That's why it didn't work.
kevin9999, thank you and no problem at all there would be definitely some larger formula which will work with my version let wait if some one can come across.

Kind Regards
Moti
 
Upvote 0
All-F11 to open VBA windows. Insert new modul then past below code. Hit F5 to run.
VBA Code:
Option Explicit
Sub test()
Dim Lr, i, j, k As Long
Dim dic As Object
Dim rng, key As Variant
Dim st As String
Set dic = CreateObject("Scripting.dictionary")
Lr = Cells(Rows.Count, "B").End(xlUp).Row ' dynamic range
For i = 6 To Lr
    k = 0
    st = ""
    For j = 1 To 5 ' adjust 5 to last column, if needed
    rng = Range("B" & i).Offset(, j - 1).Value
        If Not dic.exists(rng) Then ' create list of unique number
        k = k + 1
        dic.Add rng, k
        End If
    Next
    For Each key In dic.keys ' loop through each unique value then concatenate
    st = st & key & "|"
    Next
    Range("H" & i).Value = Left(st, Len(st) - 1) 'write down to cell
    dic.RemoveAll
Next
End Sub
 
Upvote 0
All-F11 to open VBA windows. Insert new modul then past below code. Hit F5 to run.
VBA Code:
Option Explicit
Sub test()
Dim Lr, i, j, k As Long
Dim dic As Object
Dim rng, key As Variant
Dim st As String
Set dic = CreateObject("Scripting.dictionary")
Lr = Cells(Rows.Count, "B").End(xlUp).Row ' dynamic range
For i = 6 To Lr
    k = 0
    st = ""
    For j = 1 To 5 ' adjust 5 to last column, if needed
    rng = Range("B" & i).Offset(, j - 1).Value
        If Not dic.exists(rng) Then ' create list of unique number
        k = k + 1
        dic.Add rng, k
        End If
    Next
    For Each key In dic.keys ' loop through each unique value then concatenate
    st = st & key & "|"
    Next
    Range("H" & i).Value = Left(st, Len(st) - 1) 'write down to cell
    dic.RemoveAll
Next
End Sub
Wow! bebo021999, special VBA coding worked like magic! And you written an easy way so any one can change the address very easily

I appreciate you help I like the macro (y)

Good Luck

Kind Regards
Moti :)
 
Upvote 0
Pease suggest formula or VBA
Since you also asked for a formula suggestion and you only have 5 columns it would be feasible to use standard worksheet functions.

21 12 09.xlsm
BCDEFGH
5n1n2n3n4n5
6881821218 | 18 | 21
72202025252 | 20 | 25
82101013132 | 10 | 13
9351123253 | 5 | 11 | 23 | 25
10121116201 | 2 | 11 | 16 | 20
118151920258 | 15 | 19 | 20 | 25
12361821223 | 6 | 18 | 21 | 22
131445241 | 4 | 5 | 24
142121214172 | 12 | 14 | 17
151121420221 | 12 | 14 | 20 | 22
162111517182 | 11 | 15 | 17 | 18
1713610221 | 3 | 6 | 10 | 22
18551019255 | 10 | 19 | 25
1935514183 | 5 | 14 | 18
20181821232518 | 21 | 23 | 25
21131315252513 | 15 | 25
227121221217 | 12 | 21
23161111151 | 6 | 11 | 15
24561010125 | 6 | 10 | 12
25131819192113 | 18 | 19 | 21
26261214182 | 6 | 12 | 14 | 18
2712510121 | 2 | 5 | 10 | 12
2822722252 | 7 | 22 | 25
29362424253 | 6 | 24 | 25
30451416174 | 5 | 14 | 16 | 17
31381218223 | 8 | 12 | 18 | 22
32101421222510 | 14 | 21 | 22 | 25
332141522222 | 14 | 15 | 22
34131321222413 | 21 | 22 | 24
35691616206 | 9 | 16 | 20
Join
Cell Formulas
RangeFormula
H6:H35H6=B6&IF(C6<>B6," | "&C6,"")&IF(MATCH(D6,B6:D6,0)=3," | "&D6,"")&IF(MATCH(E6,B6:E6,0)=4," | "&E6,"")&IF(MATCH(F6,B6:F6,0)=5," | "&F6,"")
 
Upvote 0
Solution
Actually, if the numbers are ascending in each row like your samples, then this should do it.

21 12 09.xlsm
BCDEFGH
5n1n2n3n4n5
6881821218 | 18 | 21
72202025252 | 20 | 25
82101013132 | 10 | 13
9351123253 | 5 | 11 | 23 | 25
10121116201 | 2 | 11 | 16 | 20
118151920258 | 15 | 19 | 20 | 25
12361821223 | 6 | 18 | 21 | 22
131445241 | 4 | 5 | 24
142121214172 | 12 | 14 | 17
151121420221 | 12 | 14 | 20 | 22
162111517182 | 11 | 15 | 17 | 18
1713610221 | 3 | 6 | 10 | 22
18551019255 | 10 | 19 | 25
1935514183 | 5 | 14 | 18
20181821232518 | 21 | 23 | 25
21131315252513 | 15 | 25
227121221217 | 12 | 21
23161111151 | 6 | 11 | 15
24561010125 | 6 | 10 | 12
25131819192113 | 18 | 19 | 21
26261214182 | 6 | 12 | 14 | 18
2712510121 | 2 | 5 | 10 | 12
2822722252 | 7 | 22 | 25
29362424253 | 6 | 24 | 25
30451416174 | 5 | 14 | 16 | 17
31381218223 | 8 | 12 | 18 | 22
32101421222510 | 14 | 21 | 22 | 25
332141522222 | 14 | 15 | 22
34131321222413 | 21 | 22 | 24
35691616206 | 9 | 16 | 20
Join (2)
Cell Formulas
RangeFormula
H6:H35H6=B6&IF(C6<>B6," | "&C6,"")&IF(D6<>C6," | "&D6,"")&IF(E6<>D6," | "&E6,"")&IF(F6<>E6," | "&F6,"")
 
Upvote 0

Forum statistics

Threads
1,215,055
Messages
6,122,902
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