search and delete multiple item separated by a comma

BORUCH

Well-known Member
Joined
Mar 1, 2016
Messages
528
Office Version
  1. 365
Platform
  1. Windows
HI

I have this code below

Code:
Sub DeleteRows()
    Dim c As Range
    Dim SrchRng As Range
    Dim SrchStr As String
Dim SrchStr2 As String
    SrchStr2 = InputBox("Please Enter A column to search")
    Set SrchRng = ActiveSheet.Range(SrchStr2 & "1", ActiveSheet.Range(SrchStr2 & "104875").End(xlUp))
    SrchStr = InputBox("Please Enter A Search String")
    Do
        Set c = SrchRng.Find(SrchStr, LookIn:=xlValues)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
 
End Sub



I would like to add to the second input box that you should be able To put in multiple items separated by a comma, and it should perform this macro if it finds any of theses values

THANKS
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Code:
Sub DeleteRows()
Dim c As Range
Dim SrchRng As Range
Dim SrchStr As String
Dim SrchStr2 As String
Dim ray As Variant, i%
SrchStr2 = InputBox("Please Enter A column to search")
Set SrchRng = ActiveSheet.Range(SrchStr2 & "1", ActiveSheet.Range(SrchStr2 & "104875").End(xlUp))
SrchStr = Application.InputBox( _
    "List the values in this format: text,text,text,...", Type:=2)
ray = Split(SrchStr, ",")
For i = 0 To UBound(ray)
    Do
        Set c = SrchRng.Find(What:=ray(i), After:=SrchRng(1), LookIn:=xlValues, LookAt:=xlWhole, _
            SearchDirection:=xlPrevious, MatchCase:=False)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
Next
End Sub

You might want to add error handlers for the input boxes to cover when Cancel is pressed or an invalid value is input.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,793
Members
449,048
Latest member
greyangel23

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