Combine multiple columns of table data into a single column with duplicates removed

jeff_cp

Board Regular
Joined
May 21, 2015
Messages
84
I have multiple columns of data listing out employees from different divisions. Each column is a query and will have different numbers of employees and in some cases, the query can return a NULL employee. I need to combine these employees into a single column with the duplicates removed. Here is an example:

Division1Division2Division3Division4Division5Division6Division7Division8Division9Division10Division11Division12
BRIANDANNY RAYBOBBRIANJASONBRIANBRIANGINA
DAVEJASONDANNY RAYEDWARDDANNY RAYDANNY RAY
DANNY RAYJASONGINAGINAGINA
GINAKRISTENJASON
JASONKRISTEN
KRISTEN

I need to combine the employees in columns A thru L into a single list in column M and remove any duplicates. I also need to leave the NULL value if it exists in any of the queries. The resulting list would look like this:

Employees
BOB
BRIAN
DANNY RAY
DAVE
EDWARD
GINA
JASON
KRISTEN
NULL

I need VBA to do this as I want this to occur when I open the spreadsheet. I have each of the 12 queries set to run when I open the spreadsheet so they will be populated. I need the VBA to produce a list of unique employees that I can use in another worksheet with getpivotdata formulas to summarize some data on other worksheets.

Thanks in advance for any help with this.
 
another option with
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Source, {}, "Attribute", "Employees"),
    TSC = Table.SelectColumns(Unpivot,{"Employees"}),
    Distinct = Table.Distinct(TSC, {"Employees"}),
    Sort = Table.Sort(Distinct,{{"Employees", Order.Ascending}})
in
    Sort
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Formula option
Press CTRL+SHIFT+ENTER to enter array formulas.
Book1
ABCDEFGHIJKL
1Division1Division2Division3Division4Division5Division6Division7Division8Division9Division10Division11Division12
2BRIANDANNY RAYBOBBRIANJASONBRIANBRIANGINA
3DAVEJASONDANNY RAYEDWARDDANNY RAYDANNY RAY
4DANNY RAYJASONGINAGINAGINA
5GINAKRISTENJASON
6JASONKRISTEN
7KRISTEN
8
9
10
11
12Employees
13BOB
14BRIAN
15DANNY RAY
16DAVE
17EDWARD
18GINA
19JASON
20KRISTEN
21 
22 
23 
24 
25 
26 
27 
Sheet2
Cell Formulas
RangeFormula
A13:A27A13=IFERROR(INDEX($A$2:$L$7,MOD(MATCH(1,(NUMBERVALUE(TRIM(MID(SUBSTITUTE(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7)))," ",REPT(" ",99)),(ROW(OFFSET($A$1,,,LEN(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7))))-LEN(SUBSTITUTE(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7)))," ",""))+1))-1)*99+((ROW(OFFSET($A$1,,,LEN(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7))))-LEN(SUBSTITUTE(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7)))," ",""))+1)))=1),99)))+NUMBERVALUE(TRIM(MID(SUBSTITUTE(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>"")))," ",REPT(" ",99)),(ROW(OFFSET($A$1,,,LEN(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>""))))-LEN(SUBSTITUTE(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>"")))," ",""))+1))-1)*99+((ROW(OFFSET($A$1,,,LEN(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>""))))-LEN(SUBSTITUTE(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>"")))," ",""))+1)))=1),99))))-SUM(COUNTIF($A$2:$L$7,A$12:A12)),0)-1,ROWS($A$2:$L$7))+1,CEILING(MATCH(1,(NUMBERVALUE(TRIM(MID(SUBSTITUTE(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7)))," ",REPT(" ",99)),(ROW(OFFSET($A$1,,,LEN(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7))))-LEN(SUBSTITUTE(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7)))," ",""))+1))-1)*99+((ROW(OFFSET($A$1,,,LEN(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7))))-LEN(SUBSTITUTE(TEXTJOIN(" ",FALSE,COUNTIF($A$2:$L$7,"<"&TRANSPOSE($A$2:$L$7)))," ",""))+1)))=1),99)))+NUMBERVALUE(TRIM(MID(SUBSTITUTE(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>"")))," ",REPT(" ",99)),(ROW(OFFSET($A$1,,,LEN(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>""))))-LEN(SUBSTITUTE(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>"")))," ",""))+1))-1)*99+((ROW(OFFSET($A$1,,,LEN(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>""))))-LEN(SUBSTITUTE(TEXTJOIN(" ",FALSE,TRANSPOSE(--($A$2:$L$7<>"")))," ",""))+1)))=1),99))))-SUM(COUNTIF($A$2:$L$7,A$12:A12)),0),ROWS($A$2:$L$7))/ROWS($A$2:$L$7)),"")
Press CTRL+SHIFT+ENTER to enter array formulas.

I am wondering how you built this formula I think it's tough like coding.
 
Upvote 0
I went with Power Query for this...pretty simple after playing around with it for a bit. Thanks Sandy.
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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