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
 
thanks again, Alex
just I want understand this
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
is it problem even I use your suggestion ?
 
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
thanks Peter for your code .;)
You're welcome. Since I had used Clear when ClearContents is apparently better for you, and I had omitted a "." I'll post the full amended code here.
If this still does what you want then you might consider amending the 'Mark as solution'.

VBA Code:
Sub Del_Rows_Amended()
  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.ClearContents
    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
You're welcome. Since I had used Clear when ClearContents is apparently better for you, and I had omitted a "." I'll post the full amended code here.
thanks, but I've found Alex Blakenburg 's suggestion doesn't work well !
from the first time will keep formatting and borders I make it manually for just specific rows and delete the borders for the rest of rows and when run the macro every time will delete borders and number format for all of rows.
 
Upvote 0
Sorry, then I don't really know what you need. :(
well, the pictures will express my problems
PIC1 I create formatting & borders also number format C: E manually
1.PNG


what I want when I run the code every time should be like this(PIC2)
2.PNG


but your code when run the first time as in PIC3 , this is what I got
3.PNG


and when run again this is what I got as in PIC4
4.PNG
 
Upvote 0
Since you have code moving the data to the OUTPUT sheet, why not have the code apply the relevant formatting to the used area as well?

On OUTPUT make sure that the heading row and row 2 have the formatting that you want. Doesn't matter about any other rows. You only have to do this once.

Now try this code a few times with different items in column G of ACS sheet.

VBA Code:
Sub Del_Rows_v4()
  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
  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 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

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