This should get you there:
Public Sub ListAssignments(ByVal rngInput As Excel.Range, ByVal rngDest As Excel.Range)
Dim scpOperators As Object
Dim arrInput As Variant
Dim arrOutput As Variant
Dim intCol As Integer
Dim intCols As Integer
Dim lngLastRow As Long
Dim lngRow As Long
Dim lngIndex As Long
intCols = rngInput.Parent.UsedRange.Offset(0, rngInput.Parent.UsedRange.Columns.Count - 1).Column
arrInput = rngInput.Resize(1, intCols - rngInput.Column + 1)
For intCol = LBound(arrInput, 2) To UBound(arrInput, 2)
If arrInput(1, intCol) = "" Then
Exit For
End If
Next intCol
If intCol > UBound(arrInput, 2) Then
intCols = UBound(arrInput, 2)
Else
intCols = intCol
End If
intCol = rngInput.Column
On Error Resume Next
lngLastRow = rngInput.Parent.Columns(intCol).Find(What:="*", _
After:=rngInput.Parent.Cells(1, intCol), _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
LookAt:=xlPart, LookIn:=xlValues).Row
If Err <> 0 Then
lngLastRow = 0
End If
On Error GoTo 0
If lngLastRow > rngInput.Row Then
arrInput = rngInput.Offset(1, 0).Resize(lngLastRow - rngInput.Row, intCols)
Set scpOperators = CreateObject("Scripting.Dictionary")
scpOperators.CompareMode = vbTextCompare
For lngRow = LBound(arrInput) To UBound(arrInput)
For intCol = 2 To UBound(arrInput, 2)
If arrInput(lngRow, intCol) > "" Then
If Not scpOperators.Exists(arrInput(lngRow, intCol)) Then
scpOperators.Item(arrInput(lngRow, intCol)) = scpOperators.Count + 1
End If
End If
Next intCol
Next lngRow
ReDim arrOutput(1 To scpOperators.Count, 1 To 2)
lngRow = 0
For Each v In scpOperators.Keys
lngRow = lngRow + 1
arrOutput(lngRow, 1) = v
Next v
For lngRow = LBound(arrInput) To UBound(arrInput)
For intCol = 2 To UBound(arrInput, 2)
If arrInput(lngRow, intCol) > "" Then
lngIndex = scpOperators.Item(arrInput(lngRow, intCol))
If arrOutput(lngIndex, 2) > "" Then
arrOutput(lngIndex, 2) = arrOutput(lngIndex, 2) & ","
End If
arrOutput(lngIndex, 2) = arrOutput(lngIndex, 2) & arrInput(lngRow, 1)
End If
Next intCol
Next lngRow
intCol = rngDest.Column
On Error Resume Next
lngLastRow = rngDest.Parent.Columns(intCol).Find(What:="*", _
After:=rngDest.Parent.Cells(1, intCol), _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
LookAt:=xlPart, LookIn:=xlValues).Row
If Err <> 0 Then
lngLastRow = rngDest.Row + 1
End If
rngDest.Offset(1, 0).Resize(lngLastRow - rngDest.Row, 2).ClearContents
rngDest.Offset(1, 0).Resize(UBound(arrOutput), 2) = arrOutput
End If
End Sub
A bit long, but I try to make robust code. Call it like this:
Call ListAssignments(Worksheets("Sheet1").Range("A1"), Worksheets("Sheet2").Range("A1"))
where Sheet1!A1 is the top-left cell of the input range, and Sheet2!A1 is the top left cell of the output range.
The code first finds out how many columns of input data you have, then how many rows, and moves the input data into arrInput. Then it looks through the input array, building an index of operators. Next, it builds an output array based on the number of operators, moves the operator names into it, then builds strings with the Machine numbers. And, finally, it clears out any information previously in the destination and moves the array to the destination.