remove duplicates with conditions
<p>I have a data chart that i update every week. when i add new data i need to delete the duplicate data. but there are conditions, rules what to delete and what not.
in the pictures i explain.
basically i need to manually see if the new data (in yellow) has the same numbers,names,dates and values.</p>

<p>if all data above is the same then its a simple delete duplicate. but if there are some data that isn't the same as the old data i need to keep it. and i also need to keep the data that has the most hours out of the duplicates.(column c)</p>

<p>geez..it sounds crazy but i manged to record a macro (whats in the pictures)</p>

<pre><code>Sub Macro20() ActiveWorkbook.Worksheets("excel").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("excel").Sort.SortFields.Add Key:=Range("A2:A80"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortTextAsNumbers
ActiveWorkbook.Worksheets("excel").Sort.SortFields.Add Key:=Range("G2:G80"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("excel").Sort
    .SetRange Range("A1:P80")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
ActiveSheet.Range("$A$1:$P$80").RemoveDuplicates Columns:=Array(1, 2, 5, 6, 7), _
    Header:=xlYes  End Sub
</code></pre>

<p>the problem here is that is dosent keep the highest hour, and that the range isnt dynamic</p>

<p>and i made a code - only that the code dosent keep the biggest number in hours.
im so close!! what am i missing?   </p>

<pre><code>Sub DeleteTheDoops()
Dim RowNdx As Long 
For RowNdx = Range("A1:G1").End(xlDown).Row To 2 Step -1
If Cells(RowNdx, "A").Value = Cells(RowNdx - 1, "A").Value Then
 If Cells(RowNdx, "F").Value = Cells(RowNdx - 1, "F").Value Then
    If Cells(RowNdx, "C").Value &lt;= Cells(RowNdx - 1, "C").Value Then
    If Cells(RowNdx, "E").Value &lt;= Cells(RowNdx - 1, "E").Value Then
       Rows(RowNdx).Delete
    Else
        Rows(RowNdx - 1).Delete
    End If
End If 
End If 
End IfNext RowNdx
End Sub
</code></pre>

<p>im kinda lost. hope i was clear. thank you !!</p>

<p><a href="https://i.stack.imgur.com/XWk3r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XWk3r.png" alt="1"></a></p>

<p><a href="https://i.stack.imgur.com/0VtlM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0VtlM.png" alt="2"></a></p>

<p><a href="https://i.stack.imgur.com/0V9uB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0V9uB.png" alt="3"></a></p>

<p><a href="https://i.stack.imgur.com/0aOWe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0aOWe.png" alt="4"></a></p>