Hello & Welcome to the Board,
This is the best I can come up with...
Change sheet names to meet your needs...
Right now it is Sheet2 as the data and Sheet3 as the output
Sub Macro1A()
Dim Cell As Range
Dim Data As Variant
Dim Dict As Object
Dim DstRng As Range
Dim Key As Variant
Dim Item As Variant
Dim R As Long
Dim Rng As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Dim i As Long
Set Wks = Worksheets("Sheet2")
Set Rng = Wks.Range("A2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))
Set DstRng = Worksheets("Sheet3").Range("A1")
Set Dict = CreateObject("Scripting.Dictionary")
Dict.CompareMode = vbTextCompare
For Each Cell In Rng
Key = Trim(Cell)
Item = Cell.Offset(0, 1)
If Not Dict.Exists(Key) Then
Dict.Add Key, Item
Else
Dict(Key) = Dict(Key) & "|" & Item
End If
Next Cell
For Each Key In Dict.Keys
With DstRng.Offset(R, 0)
.Value = Key
Data = Split(Dict(Key), "|")
.Offset(0, 1).Resize(1, UBound(Data) + 1).Value = Data
R = R + 1
End With
Next Key
Columns("B:B").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
Cells(i, 2).FormulaR1C1 = "=COUNTA(RC[1]:RC[100])"
Next i
End Sub
Bookmarks