VBA Delete Rows incl Case Sensitive

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
184
Office Version
  1. 2013
Hi All,

I am looking to delete rows containing the letter "S" in column C, and containing "cost", "ref" or "spare" anywhere in the string. I think I have the code sorted from research but can you help make it ignore case sensitivity?

Thanks

Code:
Sub test()
    Application.ScreenUpdating = False  
    Dim i&

i = Range("D" & Rows.Count).End(xlUp).Row
While i <> 1
With Cells(i, 4)
If (.value Like "*cost*" _
Or .value Like "*ref*" _
Or .value Like "*spare") _
Then
Rows(i).Delete
End If
End With
        i = i - 1
    Wend
    Dim i&

i = Range("C" & Rows.Count).End(xlUp).Row
While i <> 1
With Cells(i, 3)
If .value Like "*S*" _
Then
Rows(i).Delete
End If
End With
        i = i - 1
    Wend

    Application.ScreenUpdating = True
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
How about
VBA Code:
Sub horizonflame()
    With ActiveSheet
        .Range("A1:D1").AutoFilter 4, "*s*", xlOr, "*ref*"
        .AutoFilter.Range.Offset(1).EntireRow.Delete
        .AutoFilterMode = False
    End With
End Sub
 
Upvote 0
Hi Fluff,

Thank you but that misses off my other criteria. (I should have put "cost", "ref" or "spare" is in Column D and "*s*" in Column C)

Thanks
 
Upvote 0
Apologies, missed the cat that S was in a different column.
What is the last column in your data & is that fixed?
 
Upvote 0
Try this.
Code:
Sub test()
Dim I As Long

    Application.ScreenUpdating = False

    I = Range("D" & Rows.Count).End(xlUp).Row
    While I <> 1
        With Cells(I, 4)
            If (UCase(.Value) Like "*COST*" _
                Or UCase(.Value) Like "*REF*" _
                Or UCase(.Value) Like "*SPARE") _
                Or UCase(.Offset(, -1).Value) Like "*S*" _
                Then
                Rows(I).Delete
            End If
        End With
        I = I - 1
    Wend

    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Ok, how about
VBA Code:
Sub horizonflame()
    With ActiveSheet
        .Range("X2:X" & .Range("A" & Rows.Count).End(xlUp).Row).Formula = "=OR(ISNUMBER(SEARCH(""S"",C2)),ISNUMBER(SEARCH({""*ref*"",""*spare*"",""*cost*""},D2)))"
        .Range("A1:X1").AutoFilter 24, True
        .AutoFilter.Range.Offset(1).EntireRow.Delete
        .AutoFilterMode = False
        .Range("X:X").ClearContents
    End With
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

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