Macro to Delete rows based on criteria

tjc154

Active Member
Joined
Apr 7, 2007
Messages
363
I need a macro that removes all rows in column A that contain the following text string in the cell.

AUML
AZCF
AZEF
AZGR
UKRCDR
SGSG

Thanks,

Tom
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Code:
Public Sub ProcessData()
Const TEST_COLUMN As String = "A"       '<<<< change to suit
Dim Lastrow As Long
Dim i As Long

    Application.ScreenUpdating = False
    
    With ActiveSheet
    
        Lastrow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
        For i = Lastrow To 1 Step -1
        
            If Cells(i, TEST_COLUMN).Value2 Like "*AUML*" Or _
                Cells(i, TEST_COLUMN).Value2 Like "*AZCF*" Or _
                Cells(i, TEST_COLUMN).Value2 Like "*AZEF*" Or _
                Cells(i, TEST_COLUMN).Value2 Like "*AZGR*" Or _
                Cells(i, TEST_COLUMN).Value2 Like "*UKRCDR*" Or _
                Cells(i, TEST_COLUMN).Value2 Like "*SGSG*" Then
            
                .Rows(i).Delete
            End If
        Next i
    End With
    
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I created a separate thread for multiple line continuations. My response was to the previous thread. The site admin closed out the thread and asked that I post to this thread. Please disregard.

Thanks,

Tom
 
Upvote 0
xld,

I did have one question. Since I am unable to exceed more than 24 statements, I would like to duplicate the code you provided and run this as single macro. I have a total of 42 statement, so I would essentially replicate the code for statements 25-42, but just modify the search string values.

Cells(i, TEST_COLUMN).Value2 Like "*ABCD*" Or _

How do I create this as a single macro? I thought using a Call function would work, but it makes sense, its a separate sub routine.

Thanks,

Tom
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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