It was mentioned way back in posts 18 & 19
Yes, vba, also mentioned before. This time I have used a User-Defined Function (UDF). I have still also employed an extra column. This could be achieved with vba and without the helper column but the function would be slower to calculate with large ranges. Post back if you want that option though.
Data sheet with the helper column
shafiey.xlsm |
---|
|
---|
| A | B | C | D | E |
---|
1 | Col01 | Col02 | Col03 | Col04 | |
---|
2 | a | b, c | d, e, f | g, h, i, j | 4 |
---|
3 | a | | d, e, f | g, h, i, j | 3 |
---|
4 | a | b, c | d, e, f | g, h, i, j | 4 |
---|
5 | | | | | 0 |
---|
6 | a | b, c | d, e, f | g, h, i, j | 4 |
---|
7 | a | b, c | d, e, f | g, h, i, j | 4 |
---|
8 | | b, c | d, e, f | g, h, i, j | 3 |
---|
9 | a | b, c | d, e, f | g, h, i, j | 4 |
---|
10 | a | b, c | d, e, f | g, h,x, j | 4 |
---|
11 | a | b, c | d, e, f | g, h, i, j | 4 |
---|
|
---|
To implement the UDF
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below (top cell in each column only)
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)
VBA Code:
Function ListItems(r As Range, Optional RemoveDupes As Boolean = False) As Variant
Dim a As Variant, itm As Variant
Dim i As Long, cols As Long
a = r.Value
cols = UBound(a, 2)
With CreateObject("System.Collections.ArrayList")
For i = 1 To UBound(a)
If a(i, cols) > 0 Then
For Each itm In Split(Replace(Application.TextJoin(",", 1, Application.Index(a, i, Application.Sequence(cols - 1))), " ", ""), ",")
If RemoveDupes Then
If Not .Contains(itm) Then .Add itm
Else
.Add itm
End If
Next itm
End If
Next i
.Sort
If .Count > 0 Then ListItems = Application.Transpose(.ToArray)
End With
End Function
shafiey.xlsm |
---|
|
---|
| A | B |
---|
1 | Duplicates | without Duplicates |
---|
2 | a | a |
---|
3 | a | b |
---|
4 | a | c |
---|
5 | a | d |
---|
6 | a | e |
---|
7 | a | f |
---|
8 | a | g |
---|
9 | a | h |
---|
10 | a | i |
---|
11 | b | j |
---|
12 | b | x |
---|
13 | b | |
---|
14 | b | |
---|
15 | b | |
---|
16 | b | |
---|
17 | b | |
---|
18 | b | |
---|
19 | c | |
---|
20 | c | |
---|
21 | c | |
---|
22 | c | |
---|
23 | c | |
---|
24 | c | |
---|
25 | c | |
---|
26 | c | |
---|
27 | d | |
---|
28 | d | |
---|
29 | d | |
---|
30 | d | |
---|
31 | d | |
---|
32 | d | |
---|
33 | d | |
---|
34 | d | |
---|
35 | d | |
---|
36 | e | |
---|
37 | e | |
---|
38 | e | |
---|
39 | e | |
---|
40 | e | |
---|
41 | e | |
---|
42 | e | |
---|
43 | e | |
---|
44 | e | |
---|
45 | f | |
---|
46 | f | |
---|
47 | f | |
---|
48 | f | |
---|
49 | f | |
---|
50 | f | |
---|
51 | f | |
---|
52 | f | |
---|
53 | f | |
---|
54 | g | |
---|
55 | g | |
---|
56 | g | |
---|
57 | g | |
---|
58 | g | |
---|
59 | g | |
---|
60 | g | |
---|
61 | g | |
---|
62 | g | |
---|
63 | h | |
---|
64 | h | |
---|
65 | h | |
---|
66 | h | |
---|
67 | h | |
---|
68 | h | |
---|
69 | h | |
---|
70 | h | |
---|
71 | h | |
---|
72 | i | |
---|
73 | i | |
---|
74 | i | |
---|
75 | i | |
---|
76 | i | |
---|
77 | i | |
---|
78 | i | |
---|
79 | i | |
---|
80 | j | |
---|
81 | j | |
---|
82 | j | |
---|
83 | j | |
---|
84 | j | |
---|
85 | j | |
---|
86 | j | |
---|
87 | j | |
---|
88 | j | |
---|
89 | x | |
---|
90 | | |
---|
|
---|