VBA help-delete multiple string

Isabella

Well-known Member
Joined
Nov 7, 2008
Messages
643
Hi, i am after a vba code that will delete, BULK, MISC, FORWARD and OFFICE

Excel Workbook
C
1CODE
2BERZINS
3MISC
4MISC
5BARNES
6CASTLE
7GESHOSG
8ERDMAN
9OFFICE
10BATEMAN
11BULK
12BULK
13MASTERS
14FORWARD
15ORLEYM
Sheet1
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Maybe:
Rich (BB code):
Option Explicit
    
Sub exa1()
Dim REX As Object
Dim lLRow As Long, i As Long
    lLRow = Cells(Rows.Count, "A").End(xlUp).Row
    If lLRow < 2 Then Exit Sub
    Set REX = CreateObject("VBScript.RegExp")
    With REX
        .Global = False
        .IgnoreCase = True '<---change to suit
        .Pattern = "^(MISC|OFFICE|BULK|FORWARD)$"
        For i = lLRow To 2 Step -1
            If .Test(Cells(i, "A").Value) Then Rows(i).Delete
        Next
    End With
End Sub
Hope that helps,

Mark
 
Upvote 0
Hi,

Maybe:

Code:
Sub RemoveValues()

    Dim rngCell As Range
    Dim lngLastRow As Long, lngRow As Long
    
    lngLastRow = Range("C" & Rows.Count).End(xlUp).Row
    
    For lngRow = lngLastRow To 2 Step -1
        Select Case Range("C" & lngRow)
            Case "MISC", "OFFICE", "BULK", "FORWARD"
                Range("C" & lngRow).Delete Shift:=xlUp
        End Select
    Next lngRow

End Sub
 
Upvote 0
Mark, why use .Test?

Maybe:
Rich (BB code):
Option Explicit
    
Sub exa1()
Dim REX As Object
Dim lLRow As Long, i As Long
    lLRow = Cells(Rows.Count, "A").End(xlUp).Row
    If lLRow < 2 Then Exit Sub
    Set REX = CreateObject("VBScript.RegExp")
    With REX
        .Global = False
        .IgnoreCase = True '<---change to suit
        .Pattern = "^(MISC|OFFICE|BULK|FORWARD)$"
        For i = lLRow To 2 Step -1
            If .Test(Cells(i, "A").Value) Then Rows(i).Delete
        Next
    End With
End Sub
Hope that helps,

Mark
 
Upvote 0
Hi Isabella,

.Test returns TRUE if we made a match; where the match could be any of the values in the pattern. The ^$ denote the start and end of the string, so we make sure we don't falsely match BULKHEAD or such.

That said, I would use Mike's.

Mark
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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