こんにちは。
ややベタですが、VBA的にはよく使われる基本テクに則した書き方です。
Sub Re8953225()
Dim wks2 As Worksheet
Dim sClass As String
Dim nRow As Long, nCol As Long, i As Long
Set wks2 = Sheets("Sheet2")
With Sheets("Sheet1")
nRow = 0
sClass = ""
For i = 1 To .Cells(Rows.Count, "A").End(xlUp).Row
If .Cells(i, "B") <> sClass Then
sClass = .Cells(i, "B")
nRow = nRow + 1
wks2.Cells(nRow, 1) = .Cells(i, "B")
nCol = 1
End If
nCol = nCol + 1
wks2.Cells(nRow, nCol) = .Cells(i, "A")
Next i
End With
End Sub