Unique List from 2 Columns Using TextJoin and Unique if possible

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,171
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I use TextJoin and Unique to get Unique data in 1 cell. What I am looking to do is is to get unique data from 2 columns into 1 cell. In D1: Steve, Mike, Jay, Mary, Ray, Al

This is the formula that I use for 1 cell: =TEXTJOIN(", ",,UNIQUE(A1:A5)). I would like to do something like, =TEXTJOIN(", ",,UNIQUE(A1:B5)) in 1 cell. Thanks in advance!!!!

Book1
AB
1SteveRay
2SteveMike
3MikeMike
4JaySteve
5MaryAL
Sheet2


 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi, try this

Book1
ABC
1SteveRay
2SteveMike
3MikeMike
4JaySteve
5MaryAL
6
Stephen_IV


VBA Code:
Option Explicit

'by Hernan Torres (Mikel ERP)
'December 13, 2019
'Refer to Stephen_IV sheet
'topic: Unique List from 2 Columns Using TextJoin and Unique if possible

Sub extraer_unicos_desde_rango()
  Dim lastRow As Long, lastCol As Long
  Dim start_b As Range
  Dim b() As Variant
  Dim element, runAll, getKeys As Variant
 
  Range("A1").Activate   'you can adapt this range, like you want
  lastRow = Sheets("Stephen_IV").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  lastCol = Sheets("Stephen_IV").Cells(1, Columns.Count).End(xlToLeft).Column
  Set start_b = Range(Cells(ActiveCell.Column, ActiveCell.Row).Address)
  'Next: two ways for create our array, in this case, I take second option
  'b = Range(start_b, Cells(Rows.Count, start_b.Column).End(xlUp)) 'crea un array y lo guarda en la variable "b"
  b = Range(start_b, Cells(lastRow, lastCol))
  With CreateObject("Scripting.Dictionary")
    For Each element In b
    runAll = .Item(element)
    Next
    getKeys = .keys
    Cells(1, 4) = Join(.keys, ",")  'because you want it, in range D1
    MsgBox "Uniques values created", vbInformation, "Mikel ERP by htorres"
  End With
End Sub
 
Upvote 0
[…]

This is the formula that I use for 1 cell: =TEXTJOIN(", ",,UNIQUE(A1:A5)). I would like to do something like, =TEXTJOIN(", ",,UNIQUE(A1:B5)) in 1 cell. Thanks in advance!!!!

[…]

What does UNIQUE(A1:B5) exactly return? Choose this bit on the formula bar, appy F9, copy what you see, and paste it here.

By the way, did you apply control+shift+enter to the formula involving A1:B5?
 
Upvote 0
Hi Aladin,

This is what I get
{"Steve","Ray";"Steve","Mike";"Mike","Mike";"Jay","Steve";"Mary","AL"}

I did try cse. Did not work.
 
Upvote 0
Please try this

=TEXTJOIN(", ",,UNIQUE(INDEX(A1:B5,MOD(SEQUENCE(ROWS(A1:B5)*COLUMNS(A1:B5),,0),ROWS(A1:B5))+1,INT(SEQUENCE(ROWS(A1:B5)*COLUMNS(A1:B5),,0)/ROWS(A1:B5))+1)))
 
Upvote 0
Bo_Ry, Thank you so much!!! That did it! That is the formula approach I was looking for. Thanks hernantorres23 yes I did and the code worked. Thank you so much for that.
 
Upvote 0
A peculiar behavior I must say...
Nope, just what you would expect. There is a second argument to UNIQUE(), if omitted or false, returns unique rows, and if true returns unique columns. Each row is distinct (each pair of cells is unique), so the entire input range is returned.
 
Upvote 0
This may not scale up as well as Bo_Ry's formula, but does provide a simpler formula for a smallish range with shortish texts.

Book1
ABCD
1SteveRaySteve, Ray, Mike, Jay, Mary, AL
2SteveMike
3MikeMike
4JaySteve
5MaryAL
Unique
Cell Formulas
RangeFormula
D1D1=TEXTJOIN(", ",,UNIQUE(TRIM(MID(TEXTJOIN(REPT(" ",100),1,A1:B5),SEQUENCE(,COUNTA(A1:B5),1,100),100)),1))
 
Upvote 0

Forum statistics

Threads
1,215,635
Messages
6,125,940
Members
449,275
Latest member
jacob_mcbride

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