Hi
Using your example file:
E2: =SUMPRODUCT(--($B$2:$B$42=F2),--($C$2:$C$42=G2),--($D$2:$D$42=H2),ROW($D$2:$D$42))
Copy down to E42
Select the range E2:AE42
Data, Sort, Sort by column E, smallest to largest.
This will sort your data based on the row it should align against. Is this the correct order of the output? If so, then what do you want to do with the non matching items?
Sub aaa()
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
Range("E2").Formula = "=SUMPRODUCT(--($B$2:$B$" & lastrow & "=F2),--($C$2:$C$" & lastrow & "=G2),--($D$2:$D$" & lastrow & "=H2),ROW($D$2:$D$" & lastrow & "))"
Range("E2").AutoFill Destination:=Range("E2:E" & lastrow)
Range("E2:AE" & lastrow).Sort key1:=Range("E2"), order1:=xlAscending
cntzero = WorksheetFunction.CountIf(Range("E:E"), 0)
Range("A2").Resize(cntzero, 4).Insert shift:=xlDown
For i = 2 + cntzero To Cells(Rows.Count, 5).End(xlUp).Row
If Cells(i, "E") <> i Then
Cells(i, "E").Resize(1, 27).Insert shift:=xlDown
Cells(i, "E").Resize(1, 27).Interior.ColorIndex = xlNone
End If
Next i
End Sub
rylo
Bookmarks