There may well be some kind of array formula which can extract the numbers
you want but somebody else would have to help us with that.
However, assuming your data is in Column A starting in row 1, Column B is
empty and you want to delete the entire rows where you have numbers that
cancel each other out then this macro should work. NB save your work before
running this - there will be no undo afterwards.
Sub DelThese()
Dim lRow As Long
Dim colA As Range
Dim Cell As Range
Dim Mtch As Range
Dim l As Long
Application.ScreenUpdating = False
lRow = Cells(Rows.Count, 1).End(xlUp).Row
Set colA = Range(Cells(1, 1), Cells(lRow, 1))
For Each Cell In colA
If Cell.Offset(0, 1).Value = Empty Then
Set Mtch = Columns(1).Find(Cell.Value * -1)
If Not Mtch Is Nothing Then
If Mtch.Offset(0, 1).Value = Empty Then
Cell.Offset(0, 1).Value = True
Mtch.Offset(0, 1).Value = True
Else
Cell.Offset(0, 1).Value = False
End If
Else
Cell.Offset(0, 1).Value = False
End If
End If
Next Cell
For l = lRow To 1 Step -1
If Cells(l, 2).Value Then
Cells(l, 2).EntireRow.Delete
End If
Next l
Columns(2).ClearContents
Application.ScreenUpdating = True
End Sub
Note: If you have more than one set of the same offsetting numbers only one
set will be deleted. You can simply run the macro again to delete the other
set.
Hope this helps
Rowan
"chom krusopon" wrote:
I have a total column that contains several positive and negative numbers
that offset one another. Example:
Total
123
523
153
-523
-123
Is there a way to write a formula so that excel will delete all the numbers
that wash each other and leaves only numbers that are stand alone. From the
example above it will be $153. Please help ASAP. I have a big worksheet that
has well over 1,000 roles of mixed numbers that I need to delete. Thank YOu,
chom
|