The following should get you started. It assumes an input sheet named "Input" and an output sheet named "Output", all in the same workbook. Make adjustments as needed. The output sheet needs to already have headings and column formatting in place. I wasn't sure what to put in the output column A, so I just have it incrementing a sequential number.
Option Explicit
Sub CopyData()
Dim InRow As Long, OutRow As Long, OutCol As Long
Sheets("Input").Select
InRow = 4 ' 1st input data row
With Sheets("Output")
OutRow = .Range("D" & .Rows.Count).End(xlUp).Row ' Last current output row
Do Until Cells(InRow, 1).Value = ""
If Cells(InRow, 11) & Cells(InRow, 12) & Cells(InRow, 13) & Cells(InRow, 14) <> "----" Then
If Cells(InRow, 3).Value <> .Cells(OutRow, 2).Value Then ' New Code Details
OutRow = OutRow + 1 ' Create new output row
If .Cells(OutRow - 1, 1).Value = "" Then
.Cells(OutRow, 1).Value = 1
Else
.Cells(OutRow, 1).Value = .Cells(OutRow - 1, 1).Value + 1
End If
.Cells(OutRow, 2).Value = Cells(InRow, 3).Value
.Cells(OutRow, 3).Value = Cells(InRow, 1).Value
.Cells(OutRow, 4).Value = Cells(InRow, 13).Value
.Cells(OutRow, 5).Value = Cells(InRow, 12).Value
.Cells(OutRow, 6).Value = Cells(InRow, 14).Value
.Cells(OutRow, 7).Value = Cells(InRow, 11).Value
.Cells(OutRow, 17).Value = Cells(InRow, 5).Value
.Cells(OutRow, 18).Value = Cells(InRow, 6).Value
.Cells(OutRow, 19).Value = Cells(InRow, 7).Value
.Cells(OutRow, 20).Value = Cells(InRow, 8).Value
.Cells(OutRow, 21).Value = Cells(InRow, 2).Value
.Cells(OutRow, 22).Value = Cells(InRow, 4).Value
End If
Select Case Cells(InRow, 9).Value ' FB value
Case "FBR1": OutCol = 8
Case "FBR2": OutCol = 9
Case "FBR3": OutCol = 10
Case "FBR4": OutCol = 11
Case "FBR5": OutCol = 12
Case "FBR6": OutCol = 13
Case "FBR7": OutCol = 14
Case "M1": OutCol = 15
Case "E1": OutCol = 16
Case Else: OutCol = 0
End Select
If OutCol > 0 Then
.Cells(OutRow, OutCol).Value = Cells(InRow, 10).Value
End If
End If
InRow = InRow + 1
Loop
.Select
End With
End Sub
Have fun!
Bookmarks