theSquirrel
12/12/2006 9:28:00 PM
Im at work and can't really test it, but this should get you on the
right track...
Sub DeleteRows()
'declare variables
Dim r As Range
Dim rngD As Range
Set rngD = Range("D:D")
For Each r In rngD
'check to see if we have hit the end of
' the list and exit gracefully
If Len(r.Value) = 0 Then Exit For
'See if the current cell value matches
' the cell above's value
If r.Value = ActiveCell.Offset(-1, 0).Value Then
'begin checking to see if the value of
' the cell in the A column have
' similar values
If Abs(ActiveCell.Offset(0, -3).Value) =
Abs(ActiveCell.Offset(-1, -3).Value) Then
'the cells in A have the same or opposite values
ActiveCell.EntireRow.Delete
End If
End If
Next r
End Sub
Hope that helps.
theSquirrel
On Dec 12, 1:04 pm, "Virginie" <vtalm...@gmail.com> wrote:
> Hi,
>
> I am working on the following file in excel.
>
> A D
> 1 -40.07 49085
> 2 -13,320.00 49086
> 3 13,320.00 49086
> 4 -2,000.00 49089
> 5 -50.00 49091
> 6 50.00 49091
> 7 -4,154.40 49092
> 8 -65.00 49093
>
> I am trying to create a macro that will delete two lines if thet have
> the same batch number (column D) and opposite amount in column A.
>
> For example my lines 2 and 3 should be deleted and my lines 5 and 6
> should be deleted too.
>
> Thank you for your help
>
> Virginie