彼らはあなたの例に表示されるあなたの「ブロック」の値が、私はこれが動作すると思います、順番に既に存在する場合は、次の
Sub FunnySort()
Dim ws As Worksheet
Dim row, lastRow, newRow, newCol, block, oldBlock As Integer
Dim fromCell, toCell As Range
Set ws = Sheets("Sheet1")
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).row
oldBlock = ws.Range("B2").Value2
newCol = 1
For row = 3 To lastRow
block = ws.Cells(row, 2).Value2
If block = oldBlock And newCol = 1 Then
' same initial block -- don't do anything
Else
If block <> oldBlock Then
newRow = 2
newCol = newCol + 5
oldBlock = block
End If
Set fromCell = ws.Cells(newRow, newCol)
Set toCell = ws.Cells(newRow, newCol + 4)
ws.Range(fromCell, toCell).Value2 = ws.Range("A" & row & ":E" & row).Value2
newRow = newRow + 1
ws.Range("A" & row & ":E" & row).Clear
End If
Next row
End Sub
それが順序でない場合は、それが追加するのは簡単です。
また、これは、「ブロック」値が数値をスキップする(つまり3から5になる)場合、ブロックの列もスキップしないことを前提にしています。あなたの例から、私はあなたが望む行動を教えられませんでした。スキップしたい場合は、それを組み込むだけでも簡単です。