Macro, delte a row based on values in a list

TorrO

Board Regular
Joined
Feb 13, 2003
Messages
101
Office Version
  1. 2013
Platform
  1. Windows
Hi

i have a big ledger in excel. In column E i have account numbers on each line + a lot of more info.

To make a working pivot table i need to delete many lines containing some of the account numbers.

This is the ledger:
1: Bilagsnummer; Bilagsår; Bilagsbeskrivelse; Dato; Konto; beløp
2: 4;2019; Faktura fra Talkmore; 01.01.2019; 6900; 1234.-
3: 5;2019; Faktura fra Meny; 01.02.2019; 5911; 4321.-
3: like line 2 and 3 but different invoice

My list for deleting rows is account numbers like 6900, 1500, 1600, 1900 etc

I would like to delete all lines that contains one of the accounts numbers, and also remove the line (not only delete content but remove the line)
So after a run, searching for account 6900 all lines with 6900 in column E is deleted

So line 2 will disappear

Thanks!
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,727
Office Version
  1. 365
Platform
  1. Windows
Save a copy of your file, then try:
Rich (BB code):
Sub M1()
    
    Dim LR  As Long
    Dim x   As Long
    Dim v   As Variant
    v = Split("6900,1500,1600,1900", ",")

    Application.ScreenUpdating = False
    
    LR = Cells(Rows.Count, 5).End(xlUp).Row
    
    With Cells(1, 5).Resize(LR)
        For x = LBound(v) To UBound(v)
            .Replace v(x), ""
        Next x
        .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End With
    
    Application.ScreenUpdating = True
    
    Erase v
    
End Sub
Adjust part in blue for the account numbers you want
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,127,538
Messages
5,625,398
Members
416,100
Latest member
lirongr1996

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
Top