Join Only Unique Values separate By Vertical Bar

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,360
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
Actually, if the numbers are ascending in each row like your samples, ..
.. then this vba should also do it.

VBA Code:
Sub JoinThem()
  Dim a As Variant
  Dim i As Long, j As Long

  a = Range("B6", Range("B" & Rows.Count).End(xlUp)).Resize(, 5).Value
  For i = 1 To UBound(a)
    For j = 2 To 5
      If a(i, j) <> a(i, j - 1) Then a(i, 1) = a(i, 1) & " | " & a(i, j)
    Next j
  Next i
  Range("H6").Resize(UBound(a)).Value = a
End Sub
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,"")
Peter, I love the formula it worked very well I used this one because it is universal does not care for the sequence of numbers are in ascending or descending great formula

.. then this vba should also do it.

VBA Code:
Sub JoinThem()
  Dim a As Variant
  Dim i As Long, j As Long

  a = Range("B6", Range("B" & Rows.Count).End(xlUp)).Resize(, 5).Value
  For i = 1 To UBound(a)
    For j = 2 To 5
      If a(i, j) <> a(i, j - 1) Then a(i, 1) = a(i, 1) & " | " & a(i, j)
    Next j
  Next i
  Range("H6").Resize(UBound(a)).Value = a
End Sub
Peter, Also macro worked fine and noticed that has spacing in between separate By Vertical Bar great job

I appreciate you help I like the both options

Good Luck

Kind Regards
Moti :)
 
Upvote 0
You're welcome.

noticed that has spacing in between separate By Vertical Bar
My two formulas and my vba all did that because that is what you have in your column H values in post #1.

For completeness, if the numbers can be in any order in the row then my vba suggestion would change to ..

VBA Code:
Sub JoinThem_v2()
  Dim a As Variant
  Dim i As Long, j As Long

  a = Range("B6", Range("B" & Rows.Count).End(xlUp)).Resize(, 5).Value
  For i = 1 To UBound(a)
    For j = 2 To 5
      If InStr(1, " " & a(i, 1) & " ", " " & a(i, j) & " ") = 0 Then a(i, 1) = a(i, 1) & " | " & a(i, j)
    Next j
  Next i
  Range("H6").Resize(UBound(a)).Value = a
End Sub
 
Upvote 0
You're welcome.


My two formulas and my vba all did that because that is what you have in your column H values in post #1.

For completeness, if the numbers can be in any order in the row then my vba suggestion would change to ..

VBA Code:
Sub JoinThem_v2()
  Dim a As Variant
  Dim i As Long, j As Long

  a = Range("B6", Range("B" & Rows.Count).End(xlUp)).Resize(, 5).Value
  For i = 1 To UBound(a)
    For j = 2 To 5
      If InStr(1, " " & a(i, 1) & " ", " " & a(i, j) & " ") = 0 Then a(i, 1) = a(i, 1) & " | " & a(i, j)
    Next j
  Next i
  Range("H6").Resize(UBound(a)).Value = a
End Sub
Peter, thank you so much for creating macro, this worked well with the numbers, could be in any order in the row.

Have a great weekend ?

Kind Regards
Moti :)
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,956
Latest member
JPav

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