Sorry, I just noticed I had the order date targeted incorrectly. Fixed:
Sub FillOutput()
Dim OutputRow As Long
Dim LastRow As Long
Dim OrderNo As String
Dim OrderMatch As Boolean
Dim i As Long
Application.ScreenUpdating = False
LastRow = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To LastRow
If Sheets(1).Cells(i, 1).Value = OrderNo Then
OrderMatch = True
End If
OrderNo = Sheets(1).Cells(i, 1).Value
OutputRow = Sheets(2).Cells(Rows.Count, "A").End(xlUp).Row
If OrderMatch = False Then
Sheets(2).Cells(OutputRow + 1, 1).Value = "POH"
Sheets(2).Cells(OutputRow + 1, 4).Value = OrderNo
Sheets(2).Cells(OutputRow + 1, 9).Value = Sheets(1).Cells(i, 4).Value
Sheets(1).Range(Cells(i, 12), Cells(i, 15)).Copy Destination:=Sheets(2).Cells(OutputRow + 1, 36)
Sheets(2).Cells(OutputRow + 2, 1).Value = "POL"
Sheets(2).Cells(OutputRow + 2, 4).Value = Sheets(1).Cells(i, 2).Value
Sheets(2).Cells(OutputRow + 2, 5).Value = Sheets(1).Cells(i, 3).Value
Sheets(2).Cells(OutputRow + 2, 12).Value = Sheets(1).Cells(i, 7).Value
Sheets(2).Cells(OutputRow + 2, 16).Value = Sheets(1).Cells(i, 10).Value
Else
Sheets(2).Cells(OutputRow + 1, 1).Value = "POL"
Sheets(2).Cells(OutputRow + 1, 4).Value = Sheets(1).Cells(i, 2).Value
Sheets(2).Cells(OutputRow + 1, 5).Value = Sheets(1).Cells(i, 3).Value
Sheets(2).Cells(OutputRow + 1, 12).Value = Sheets(1).Cells(i, 7).Value
Sheets(2).Cells(OutputRow + 1, 16).Value = Sheets(1).Cells(i, 10).Value
End If
OrderMatch = False
Next i
Application.ScreenUpdating = True
End Sub
Bookmarks