delete 8000 rows based on what I write items in helper column

Omran Y

Board Regular
Joined
Jul 17, 2023
Messages
60
Office Version
  1. 2013
Platform
  1. Windows
Hi
I want فخ delete entire row based on helper column (G) .should match the whole item for each cell in column G with column B then should delete entire row , but be careful you will see many similar items may be you think should delete it but in reality not . should match the whole item in column G with column B. if you see the part of item is existed in column B but not whole as in column G then should not delete it.
I have about 8000 rows and every time I will add new items in column G.

OM1.xlsm
ABCDEFG
1DATEOPERATION NAMEDEBITCREDITBALANCEITEMS
201/03/2023BB IN TPUT TTR120 CASH PREPAID10,000.0010,000.00CASH PREPAID
302/03/2023 PREPAID CASH BBI-60 IN TPUT MM2002,000.0012,000.00BANK SWIFT
403/03/2023BANK SWIFT FG-100530,000.0042,000.00INVOICE NUMBER SS
504/03/2023MS.9888485 BANK SWIFT FG-100160,000.00102,000.00
605/03/2023PAID BANK MTSWF900012,000.00100,000.00
706/03/2023 SWIFT BANK FGS-10010110,000.00110,000.00
807/03/2023 CASH PREPAID BBFG IN TPUT LM704030,000.00140,000.00
908/03/2023INN702000 CASH PIAD6,000.00134,000.00
1009/03/2023CASH PIAD MN90400 UY600M1,000.00133,000.00
1110/03/2023CASH FROM CURS 1200134,200.00
1211/03/2023CSDF SWIFT REF6789992000136,200.00
1312/03/2023CRTM RT500 CVF 789/77881300137,500.00
1410/03/2023INVOICE NUMBER SS OMM-10002300139,800.00
1511/03/2023INVOICE NUMBER SS OMM-10012200142,000.00
1612/03/2023INVOICE NUMBER SS OMM-10022500144,500.00
1713/03/2023INVOICE NUMBER RR OMM-10032800147,300.00
1814/03/2023INVOICE NUMBER RR OMM-10043100150,400.00
ACS


the output should be like this
OM1.xlsm
ABCDE
1DATEOPERATION NAMEDEBITCREDITBALANCE
202/03/2023 PREPAID CASH BBI-60 IN TPUT MM2002,000.0012,000.00
305/03/2023PAID BANK MTSWF900012,000.00100,000.00
406/03/2023 SWIFT BANK FGS-10010110,000.00110,000.00
508/03/2023INN702000 CASH PIAD6,000.00134,000.00
609/03/2023CASH PIAD MN90400 UY600M1,000.00133,000.00
710/03/2023CASH FROM CURS 1200134,200.00
811/03/2023CSDF SWIFT REF6789992000136,200.00
912/03/2023CRTM RT500 CVF 789/77881300137,500.00
1013/03/2023INVOICE NUMBER RR OMM-10032800147,300.00
1114/03/2023INVOICE NUMBER RR OMM-10043100150,400.00
OUTPUT
 
@kevin9999
the code just works perfectly with small data as in OP , but with big data will stop and shows application defined error in this line
VBA Code:
d.Remove (tmp)
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
@kevin9999
the code just works perfectly with small data as in OP , but with big data will stop and shows application defined error in this line
VBA Code:
d.Remove (tmp)
Thank you for the feedback. Just curious, how big is the data you're using (8k?). I would recommend that you try Peter's code from post #10 - much more efficient than mine.
 
Upvote 0
If there are quite a few disjoint rows to delete in that range then I think that you may find this faster.
wow !
this is really fast , it gives 0.02 sec , but unfortunately implement for the same sheet 🤨
the result should be in the OUTPUT sheet
as to
this could be tried instead.
I don't think to work correctly !
just delete CASH PREPAID and gives 0.220 , so the post#8 is better.
 
Upvote 0
For speed on large data, give this version a try.

VBA Code:
Sub Del_Rows()
  Dim RX As Object
  Dim a As Variant
  Dim nc As Long, i As Long, k As Long
  
  Set RX = CreateObject("VBScript.RegExp")
  With Sheets("ACS")
    RX.Pattern = "\b(" & Join(Application.Transpose(.Range("G2", .Range("G" & Rows.Count).End(xlUp)).Value), "|") & ")\b"
    nc = 6
    a = .Range("A1:F" & .Range("A" & Rows.Count).End(xlUp).Row).Value
  End With
  For i = 2 To UBound(a)
    If RX.test(a(i, 2)) Then
      a(i, 6) = 1
      k = k + 1
    End If
  Next i
  With Sheets("OUTPUT")
    .UsedRange.Clear
    With Range("A1").Resize(UBound(a), nc)
      .Value = a
      If k > 0 Then
        Application.ScreenUpdating = False
        .Sort Key1:=.Columns(nc), Order1:=xlAscending, Header:=xlYes
        .Offset(1).Resize(k).EntireRow.Delete
        Application.ScreenUpdating = True
      End If
    End With
  End With
End Sub
 
Upvote 0
Try adding a Period "." before the With Range towards the bottom of the code.
thanks the code still fix things
the code will delete formatting and borders in OUTPUT sheet .
 
Upvote 0
You may be able to get away with changing Clear to ClearContents.
VBA Code:
    .UsedRange.ClearContents

We could bring the formatting across to the output if that doesn't work.
If you have borders inside your data set that is a little trickier, while other formatting moves with the cell when the data is sorted borders stay with the row number they are applied to. So you would need to see a visual of your, before, after and expected.
 
Upvote 0
the code will delete formatting and borders in OUTPUT sheet .
Can you clarify if that is
  • formatting that was already in the OUTPUT sheet, or
  • formatting that is in the ACS sheet that should be copied across to the OUTPUT sheet when the data gets copied?
BTW, would be good to specify all these things at the beginning rather than bit-by-bit. ;)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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