[COLOR="Navy"]Sub[/COLOR] MG28Jul43
'[COLOR="Green"][B]New Code MkII[/B][/COLOR]
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Q
[COLOR="Navy"]Dim[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Ws [COLOR="Navy"]As[/COLOR] Worksheet
[COLOR="Navy"]Dim[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Ray
[COLOR="Navy"]Dim[/COLOR] ColMax [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] k
[COLOR="Navy"]Dim[/COLOR] Wd
[COLOR="Navy"]Dim[/COLOR] tx
[COLOR="Navy"]Dim[/COLOR] t
t = Timer
Application.ScreenUpdating = False
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Ws [COLOR="Navy"]In[/COLOR] ActiveWorkbook.Worksheets
'[COLOR="Green"][B]Alter width to suit !![/B][/COLOR]
Ws.Columns("B:B").ColumnWidth = 100
[COLOR="Navy"]If[/COLOR] Not Ws.Name = "users" [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.comparemode = vbTextCompare
[COLOR="Navy"]Set[/COLOR] Rng = Ws.Range(Ws.Range("A1"), Ws.Range("A" & Rows.Count).End(xlUp))
ReDim Ray(1 To Rng.Count, 1 To 2)
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
[COLOR="Navy"]If[/COLOR] Dn > "" [COLOR="Navy"]Then[/COLOR]
Lst = Ws.Cells(Dn.Row, Columns.Count).End(xlToLeft).Column
ColMax = Application.Max(ColMax, Lst)
[COLOR="Navy"]If[/COLOR] Not .exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
Ray(1, 1) = Ws.Range(Dn.Offset(, 1), Ws.Cells(Dn.Row, Columns.Count).End(xlToLeft))
Ray(1, 2) = Lst
.Add Dn.Value, Array(Dn.Offset(, 1), Ray, 1, Lst)
[COLOR="Navy"]Else[/COLOR]
Q = .Item(Dn.Value)
Q(2) = Q(2) + 1
Q(1)(Q(2), 1) = Ws.Range(Dn.Offset(, 1), Ws.Cells(Dn.Row, Columns.Count).End(xlToLeft))
Q(1)(Q(2), 2) = Lst
[COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]Set[/COLOR] nRng = Dn
[COLOR="Navy"]Else[/COLOR]
[COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
[COLOR="Navy"]End[/COLOR] If
.Item(Dn.Value) = Q
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
'[COLOR="Green"][B]K = Each unique col "A"[/B][/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] k [COLOR="Navy"]In[/COLOR] .keys
[COLOR="Navy"]If[/COLOR] .Item(k)(3) > 1 And Not Left(.Item(k)(0), 1) = "(" [COLOR="Navy"]Then[/COLOR]
.Item(k)(0).Resize(, ColMax).Value = vbNullString
'[COLOR="Green"][B]tx = the number of rows for any one unique[/B][/COLOR]
[COLOR="Navy"]For[/COLOR] tx = 1 To .Item(k)(2)
[COLOR="Navy"]If[/COLOR] .Item(k)(1)(tx, 2) = 2 [COLOR="Navy"]Then[/COLOR]
.Item(k)(0).Value = .Item(k)(0).Value & "(" & .Item(k)(1)(tx, 1) & "),"
[COLOR="Navy"]Else[/COLOR]
'[COLOR="Green"][B]Ac = number of columns in each row for each unique[/B][/COLOR]
[COLOR="Navy"]For[/COLOR] Ac = 1 To .Item(k)(1)(tx, 2) - 1
[COLOR="Navy"]If[/COLOR] Not .Item(k)(1)(tx, 1)(1, Ac) = vbNullString [COLOR="Navy"]Then[/COLOR]
Wd = Split(.Item(k)(1)(tx, 1)(1, Ac), " ")
[COLOR="Navy"]For[/COLOR] n = 0 To UBound(Wd)
[COLOR="Navy"]If[/COLOR] Ac = 1 [COLOR="Navy"]Then[/COLOR]
.Item(k)(0).Value = .Item(k)(0).Value & "(" & Wd(n)
[COLOR="Navy"]Else[/COLOR]
.Item(k)(0).Value = .Item(k)(0).Value & "_" & Wd(n)
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Ac
.Item(k)(0).Value = .Item(k)(0).Value & "),"
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] tx
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] k
.RemoveAll
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Delete
[COLOR="Navy"]Set[/COLOR] nRng = Nothing
Lst = 0
[COLOR="Navy"]End[/COLOR] If
ColMax = 0
[COLOR="Navy"]Next[/COLOR] Ws
Application.ScreenUpdating = True
MsgBox Timer - t
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]