How do I delete matching positive and negative entries in a column

ghrek

Active Member
Joined
Jul 29, 2005
Messages
427
Hi

In column G of my workbook I have lots of positive and negative values. Im trying to get it to look all the way down column G and if there is a matching positive and negative entry of the same value I need the rows they are on completely deleting.

Any Ideas?

Thanks
 
Win 10, Excel 365 32 bit, AMD Ryzen 3 3200G, 8 GB RAM
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Thanks. The time gap between our setup seems a bit huge even if I met the same issue with several computers​
where with big data (more than 500K unique elements) using a Collection was faster than a Dictionary …​
 
Upvote 0
Little loop tweak :​
VBA Code:
Sub Demo2a()
       Const A = 7, D = 4
         Dim Rg As Range, P&, V, W, N&
         Application.ScreenUpdating = False
    With [A1].CurrentRegion.Rows
        .Sort .Cells(A), 1, .Cells(D), , 1, Header:=1
         Set Rg = .Columns(A).Find(0, , , 1)
    If Rg Is Nothing Then
        V = Application.Lookup(-0.00001, .Columns(A))
        If IsNumeric(V) Then P = .Columns(A).Find(V, , , 1, , 2).Row
    Else
          P = Rg(0).Row
       .Range(Rg, .Columns(A).Find(0, , , 1, , 2)).ClearContents
          Set Rg = Nothing
       .Sort .Cells(A), Header:=1
    End If
    If P > 1 And P < .Count Then
             .Item("2:" & P).Sort .Cells(A), 1, .Cells(D), , 2, Header:=2
        With .Range(.Cells(2, A), .Cells(A).End(xlDown))
            V = .Value2
            W = Evaluate("IF({1},INT(" & .Columns(D - A + 1).Address & "))")
        For N = P - 1 To 1 Step -1
            While V(P, 1) < -V(N, 1) And P < UBound(V):  P = P + 1:  Wend
            While V(P, 1) = -V(N, 1) And W(P, 1) < W(N, 1) And P < UBound(V):  P = P + 1:  Wend
            If V(P, 1) = -V(N, 1) Then If W(P, 1) = W(N, 1) Then V(N, 1) = Empty: V(P, 1) = Empty
            If P = UBound(V) Then If V(P, 1) < -V(N, 1) Then Exit For
        Next
           .Value2 = V
        End With
    End If
    If .Cells(A).End(xlDown).Row < .Count Then
       .Sort .Cells(A), Header:=1
       .Item(Cells(Rows.Count, A).End(xlUp)(2).Row & ":" & .Count).Clear
    End If
       .Sort .Cells(D), Header:=1
    End With
        Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Bad edit in my previous post :​
Rich (BB code):
If P > 2 And P < .Count Then
 
Upvote 0
No in fact the good version is P > 1 so post #43 is OK …​
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top