Try this
Sub Output1()
Dim ArrData As Variant, ArrResult(1 To 200, 1 To 470), i As Long, oDic As Object, sKey As String, lIndex As Long, lPos As Long
Dim lStartDate As Long, lDayPos As Long
ArrData = Sheets("raw").Range("A2:L" & Sheets("raw").Cells(&H100000, 1).End(xlUp).Row).Value2
lStartDate = Sheets("output_1").Range("K1").Value2
Sheets("output_1").UsedRange.Offset(2).ClearContents
Set oDic = CreateObject("Scripting.Dictionary")
For i = 2 To UBound(ArrData, 1)
sKey = ArrData(i, 1) & "_" & _
ArrData(i, 2) & "_" & _
ArrData(i, 3) & "_" & _
ArrData(i, 4) & "_" & _
ArrData(i, 5) & "_" & _
ArrData(i, 6) & "_" & _
ArrData(i, 8) & "_" & _
ArrData(i, 9) & "_"
If oDic.Exists(sKey) Then
lPos = oDic.Item(sKey)
If ArrData(i, 11) < ArrResult(lPos, 10) Then
ArrResult(lPos, 10) = ArrData(i, 11)
End If
Else
lIndex = lIndex + 1
oDic.Add sKey, lIndex
ArrResult(lIndex, 1) = ArrData(i, 1)
ArrResult(lIndex, 2) = ArrData(i, 8)
ArrResult(lIndex, 3) = ArrData(i, 9)
ArrResult(lIndex, 4) = ArrData(i, 5)
'ArrResult(lIndex, 5) = ArrData(i, 7)
ArrResult(lIndex, 6) = ArrData(i, 2)
ArrResult(lIndex, 7) = ArrData(i, 3)
ArrResult(lIndex, 8) = ArrData(i, 4)
ArrResult(lIndex, 9) = ArrData(i, 6)
ArrResult(lIndex, 10) = ArrData(i, 11)
lPos = lIndex
End If
lDayPos = DateDiff("m", lStartDate, ArrData(i, 11) + 1)
ArrResult(lPos, 10 + lDayPos) = ArrData(i, 10)
Next
Sheets("output_1").Range("A3").Resize(lIndex, UBound(ArrResult, 2)).Value = ArrResult
End Sub
Sub Output2()
Dim ArrData As Variant, ArrResult(1 To 10000, 1 To 12) As Variant, i As Long, j As Long, lIndex As Long
Dim lStartDate As Long, lDayPos As Long
ArrData = Sheets("output_1").Range("A1").Resize(Sheets("output_1").Cells(&H100000, 1).End(xlUp).Row, 470).Value2
lStartDate = Sheets("output_1").Range("K1").Value2
For i = 3 To UBound(ArrData, 1)
lIndex = lIndex + 1
For j = 1 To 10
ArrResult(lIndex, j) = ArrData(i, j)
Next
ArrResult(lIndex, 11) = ArrResult(lIndex, 10)
lDayPos = DateDiff("m", lStartDate, ArrResult(lIndex, 11) + 1)
ArrResult(lIndex, 12) = ArrData(i, 10 + lDayPos)
For j = 10 + lDayPos + 1 To 470
If ArrData(i, j) <> ArrData(i, j - 1) Then
lIndex = lIndex + 1
ArrResult(lIndex, 11) = ArrData(1, j)
ArrResult(lIndex, 12) = ArrData(i, j)
End If
Next
Next
Sheets("output_2").Range("B2").Resize(lIndex, 12).Value = ArrResult
End Sub
Note: Output_2 is rearranged from data of output_1. So, allway run output_1 before run output_2.
Bookmarks