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
 
why not have the code apply the relevant formatting to the used area as well?
I'm afraid the code will slow down when the big data contains formatting , so I prefer doing manually and the code just search for values .
about formatting has fixed and works very well.:)

Now try this code a few times with different items in column G of ACS sheet.
after clearing items in column G and add many times and especially when I have just item in G2 then will show mismatch error in this line .

VBA Code:
RX.Pattern = "\b(" & Join(Application.Transpose(.Range("G2", .Range("G" & Rows.Count).End(xlUp)).Value), "|") & ")\b"
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I'm afraid the code will slow down when the big data contains formatting
Have you tested that theory with my code to see how much it slows down?

when I have just item in G2 then will show mismatch error
Assuming that you will have something in G2 at least ..

VBA Code:
Sub Del_Rows_v5()
  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")
    If IsEmpty(.Range("G3").Value) Then
      RX.Pattern = "\b" & .Range("G2").Value & "\b"
    Else
      RX.Pattern = "\b(" & Join(Application.Transpose(.Range("G2", .Range("G" & Rows.Count).End(xlUp)).Value), "|") & ")\b"
    End If
    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
  Application.ScreenUpdating = False
  With Sheets("OUTPUT")
    .UsedRange.Offset(2).Clear
    With .Range("A1").Resize(UBound(a), nc)
      .Rows(2).ClearContents
      .Rows(2).Copy Destination:=.Offset(1).Resize(UBound(a) - 1)
      .Value = a
      If k > 0 Then
        .Sort Key1:=.Columns(nc), Order1:=xlAscending, Header:=xlYes
        .Offset(1).Resize(k).EntireRow.Delete
      End If
      Application.Goto .Cells(1, 1), True
    End With
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 1
Solution
Have you tested that theory with my code to see how much it slows down?
as I expected will slow down , but not big difference.
your first answer , now gives 0.16 sec
and last answer will be 0.220 sec
anyway your code is really fast , I don't expect to get better than your code with all of my respect & appreciating for others members.
thanks Peter for this great work .;)
 
Last edited:
Upvote 0
but not big difference.
your first answer , now gives 0.16 sec
and last answer will be 0.220 sec
I thought as much, 0.06 seconds difference would not even be noticeable. 😎
In any case the first code did not do the required job and the last one apparently does, so comparing the times is pretty pointless. ;)

thanks Peter
You are welcome.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
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