Or consider this VBA:
Dim i As Integer, x As Integer, r As Integer, c As Integer
With ThisWorkbook.Worksheets("Table1")
.Range("AW:BC").ClearContents
r = 3
For i = 1 To 48
c = 50
For x = 11 To 55
.Cells(r, 49) = i
If Not IsError(Application.Match(.Cells(x, i), .Range("A2:F2"), 0)) Then
.Cells(r, c) = .Cells(x, i)
c = c + 1
End If
Next
r = r + 1
Next
End With
Getting values for each output row into numerical order will require more code, probably involving an array or collection and a sort operation.
And I figured out an Excel formula to return data for a column.
Will have to modify the column letter for each row in the output range. Example for first two.
=TRANSPOSE(SORT(FILTER(A$11:A$55,COUNTIF($A$2:$F$2,A$11:A$55))))
=TRANSPOSE(SORT(FILTER(B$11:B$55,COUNTIF($A$2:$F$2,B$11:B$55))))
No idea if a single formula could be constructed to accomplish this dynamically for all columns.