delete data if the two columns contain zero together

Hasson

Active Member
Joined
Apr 8, 2021
Messages
406
Office Version
  1. 2016
Platform
  1. Windows
Hello
I have about 7000 rows . I search for way delete data contin zero or empty value for columns D,E together then should delete it.

orginal
DELETE2.xlsm
ABCDEF
1ITEMIDQTY1QTY2QTY3BALANCE
21TT/W-1 MM CLA1 23M-1 IT500500
32QQW-2 TH NM-1 CLA2 VBG L CHI0
43QQW-3 CV CLA3 TAI70033733
54QQW-4 M*12.5 CLA4 TR20012188
65QQW-5 CLA5 EG300300
76MMR12/100 AS-1000/1 TMR120012
87QQW-6 M230 TU11
98QQW-7 S** CLA7 US140011399
109QQW-8 CLA8 UK0
1110QQW-9 CLA9 N BR160011599
1211QQW-10 BN CLA10 IT80000800
1312QQW-11 LVD CH900900
1413BB12 QQW-12 CLA12 JA100011989
sheet1
Cell Formulas
RangeFormula
F2:F14F2=C2+D2-E2



result

DELETE2.xlsm
ABCDEF
1ITEMIDQTY1QTY2QTY3BALANCE
21QQW-3 CV CLA3 TAI70033733
32QQW-4 M*12.5 CLA4 TR20012188
43QQW-7 S** CLA7 US140011399
54QQW-9 CLA9 N BR160011599
65BB12 QQW-12 CLA12 JA100011989
sheet1
Cell Formulas
RangeFormula
F2:F6F2=C2+D2-E2
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
@kevin9999 your solution are fantastic !
much appreciated for that .:)
Glad we could help Hasson, and thanks for the feedback :)
Although you've marked another post as a solution, I still needed to tidy up/correct a couple of things in the code I provided. For reference only:
VBA Code:
Option Explicit
Sub Hasson_V3()
    Application.ScreenUpdating = False
    Dim LRow As Long, LCol As Long, i As Long
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("Sheet1")
    Set ws2 = Worksheets("Sheet2")
    Dim a, b
    
    ws2.UsedRange.Clear
    With ws1.Range("A1").CurrentRegion
        .Copy
        ws2.Range("A1").PasteSpecial xlPasteColumnWidths
        ws2.Range("A1").PasteSpecial xlPasteAll
        Application.CutCopyMode = False
    End With
    
    LRow = ws2.Cells.Find("*", , xlFormulas, , 1, 2).Row
    LCol = ws2.Cells.Find("*", , xlFormulas, , 2, 2).Column + 1
    
    a = ws2.Range("D2:E" & LRow)
    ReDim b(1 To UBound(a, 1), 1 To 1)
    
    For i = 1 To UBound(a)
        If a(i, 1) + a(i, 2) = 0 Then b(i, 1) = 1
    Next i
    
    ws2.Cells(2, LCol).Resize(UBound(a)) = b
    i = WorksheetFunction.Sum(Columns(LCol))
    ws2.Range(ws2.Cells(2, 1), ws2.Cells(LRow, LCol)).Sort Key1:=ws2.Cells(2, LCol), order1:=1, Header:=2
    If i > 0 Then ws2.Cells(2, LCol).Resize(i).EntireRow.Delete
    
    ws2.Columns(LCol).ClearContents
    LRow = ws2.Cells.Find("*", , xlFormulas, , 1, 2).Row
    With ws2.Range("A2:A" & LRow)
        .Formula = "=Row()-1"
        .Value = .Value
    End With
    
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
thanks again .:)
Although you've marked another post as a solution
actually that's becuase no loop and this is very fast when run the macro then , but today happens strange thing it's too slow to delete it when I want to test which code is speed to mark solution . I no know why does it now , but your code works nicely
just question why you declare some variable after set sheets ?
actually I used to declare before any setting for object .
I still needed to tidy up/correct a couple of things in the code I provided. For reference only
could old versions codes cause problem in the future?
 
Upvote 0
thanks again .:)

actually that's becuase no loop and this is very fast when run the macro then , but today happens strange thing it's too slow to delete it when I want to test which code is speed to mark solution . I no know why does it now , but your code works nicely
just question why you declare some variable after set sheets ?
actually I used to declare before any setting for object .

could old versions codes cause problem in the future?
No reason in particular, as long as you declare variables before you 'set' that variable. One school of thought is to declare variables just before you use them.
Although my code does 'loop', because it happens within an array it happens very quickly in RAM.
I would discard my first code - it doubled up the copy unnecessarily.
Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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