Sub Test()
Dim nRow As Long, nCol As Long
Dim rngRowFound As Range, rngResult As Range
Dim cell As Range, rngData As Range
Dim GotInit As Boolean, GotPDT As Boolean
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = ActiveWorkbook.Sheets(1)
Set ws2 = ActiveWorkbook.Sheets(2)
Set rngData = ws1.Range("B2", ws1.Cells(Rows.Count, "B").End(xlUp))
For Each cell In rngData
Select Case cell
Case ""
Select Case True
Case cell.Offset(0, -1) Like "Test Cycle*"
nCol = CLng(Trim(Split(cell.Offset(0, -1), "Test Cycle")(1))) + cell.Column + 1
ws2.Cells(1, nCol) = cell.Offset(0, -1)
Case cell.Offset(0, 1) = "Initialization", cell.Offset(0, 1) = "PDT"
If Not GotInit Or Not GotPDT Then
nRow = ws2.Cells(Rows.Count, "C").End(xlUp).Offset(1).row
ws2.Cells(nRow, cell.Column).Offset(0, -1) = cell.Offset(0, -1)
ws2.Cells(nRow, cell.Column).Offset(0, 1) = cell.Offset(0, 1)
End If
If cell.Offset(0, 1) = "Initialization" Then GotInit = True
If cell.Offset(0, 1) = "PDT" Then GotPDT = True
End Select
Case Else
Set rngResult = ws2.Range("B2", ws2.Cells(Rows.Count, "B").End(xlUp))
If rngResult.row = 1 Then Set rngResult = ws2.Range("B2")
Set rngRowFound = rngResult.Find(cell.Value, LookAt:=xlWhole)
If rngRowFound Is Nothing Then
nRow = ws2.Cells(Rows.Count, "C").End(xlUp).Offset(1).row
With ws2.Cells(nRow, nCol - 2)
.Offset(0, -1) = cell.Offset(0, -1)
.Value = cell
.Offset(0, 1) = cell.Offset(0, 1)
.Offset(0, 2) = cell.Offset(0, 2)
End With
Else
With ws2.Cells(rngRowFound.row, nCol)
.Value = cell.Offset(0, 2)
End With
End If
End Select
Next
End Sub