Sub getList()
Dim Cl As Range
Dim SLst As Object, Mlst As Object
Dim X As String
Set SLst = CreateObject("system.collections.arraylist")
Set Mlst = CreateObject("system.collections.arraylist")
For Each Cl In Range("A7", Range("A" & Rows.Count).End(xlUp))
If Cl.Offset(, 1).Value < Range("B4").Value Then
X = Join(Application.Index(Cl.Resize(, 3).Value, 1, 0), ",")
X = Replace(X, ",,", ",")
If Right(X, 1) = "," Then X = Left(X, Len(X) - 1)
If LCase(Cl.Offset(, 3)) = "x" Then Mlst.Add X Else SLst.Add X
ElseIf Cl.Offset(, 2) = "" Then
If LCase(Cl.Offset(, 3)) = "x" Then Mlst.Add Cl.Value Else SLst.Add Cl.Value
Else
X = Cl.Value & "," & Cl.Offset(, 2).Value
If LCase(Cl.Offset(, 3)) = "x" Then Mlst.Add X Else SLst.Add X
End If
Next Cl
Mlst.Sort
SLst.Sort
With Sheets("Output")
.Range("a2").Resize(Mlst.Count).Value = Application.Transpose(Mlst.toarray)
.Range("A" & Rows.Count).End(xlUp).Offset(1) = String(10, "-")
.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(SLst.Count).Value = Application.Transpose(SLst.toarray)
.Range("A" & Rows.Count).End(xlUp).Offset(1) = String(10, "-")
Range("E7", Range("E" & Rows.Count).End(xlUp)).Copy .Range("A" & Rows.Count).End(xlUp).Offset(1)
End With
End Sub