If you want the event names added, you're going to need to provide a complete event id / event name lookup table. This code does not add event names for that reason.
Sub simonp820()
Set ws1 = Sheets("query_result")
Set ws2 = Sheets.Add(After:=Sheets(Sheets.Count))
ws2.Name = "output " & Sheets.Count
ws1.[B1:E1].Copy ws2.[A1]
ws2.[E1].Value = "event codes"
uid = ""
r = 1
For Each c In ws1.Columns(2).SpecialCells(2, 1)
If c.Value <> uid Then
r = r + 1
Set d = c.Resize(, 4)
d.Copy ws2.Cells(r, 1)
ws2.Cells(r, 5) = c.Offset(0, -1).Value
uid = c.Value
Else
ws2.Cells(r, 5).Value = ws2.Cells(r, 5).Value & ", " & c.Offset(0, -1).Value
End If
Next
ws2.Columns.AutoFit
End Sub
Bookmarks