Hi
See how this goes. Haven't done anything about the formatting, just want to see if the output is OK.
Sub aaa()
Dim OutSH As Worksheet
Set OutSH = Sheets("Sheet2")
OutSH.Cells.ClearContents
Sheets("Sheet1").Select
For Each ce In Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row)
outrow = OutSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
OutSH.Cells(outrow, 1).Value = WorksheetFunction.CountIf(Range("H" & ce.Row & ":L" & ce.Row), "A1")
OutSH.Cells(outrow, 2).Value = ce.Offset(0, 2).Value
OutSH.Cells(outrow, 3).Value = ce.Value
OutSH.Cells(outrow, 4).Value = ce.Offset(0, 1).Value
Next ce
With OutSH
.Range("A2:D" & .Cells(Rows.Count, 1).End(xlUp).Row).Sort key1:=.Range("A2"), order1:=xlDescending, key2:=.Range("B2"), order2:=xlAscending, header:=xlNo
.Range("E2").Formula = "=SUMPRODUCT(--($A$2:$A$" & .Cells(Rows.Count, 1).End(xlUp).Row & "=A2),--($B$2:$B$" & .Cells(Rows.Count, 1).End(xlUp).Row & "=B2))"
.Range("E2").AutoFill Destination:=.Range("E2:E" & .Cells(Rows.Count, 1).End(xlUp).Row)
.Range("E:E").Value = .Range("E:E").Value
For Each ce In .Range("A3:A" & .Cells(Rows.Count, 1).End(xlUp).Row)
If ce.Offset(-1, 0).Value = ce.Value And ce.Offset(-1, 1).Value = ce.Offset(0, 1).Value Then
ce.ClearContents
ce.Offset(0, 1).ClearContents
ce.Offset(0, 4).ClearContents
End If
Next ce
End With
End Sub
rylo
Bookmarks