vb for search and delete HELP!!

theSTUDENT

New Member
Joined
Mar 31, 2011
Messages
1
Okay here is what I need. I have an excel file with a BUNCH of records (2 columns and over 100,000 rows. I need a macro to search for a string in one of the columns and if that string is found then automatically delete that whole row. The main thing is I need to be able to search for a string that may vary in the beginning but has the same ending. For example, I need both of the following strings deleted - dtd44565 and jhk34565. Both strings end in 4565 which is the 4 digit plant location # but the preceding model #'s are different(dtd4) and (jhk3). I want the code to search for and delete both of these records. (something like %4565 only I don't know vb code so I don't know if there is a symbol that can be used to search for ANY string with 4565 at the end) Can somebody PLEASE HELP??
 

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
Hi and welcome.

  • Select column A
  • Select from the menu Data|Filter|Autofilter
  • This will put a dropdown list in cell A1
  • Select from the A1 dropdown list Custom
    • Select Ends With and type in 4565
    • OK

This will hide all the rows that don't end with 4565
You can then select the visible rows and delete them

Do the same for column B
 
Upvote 0
Description: This code searches for string in the end of the Value in a cell and delete it if it is a match.

Code:
Sub chk_last_str()
Set w = ThisWorkbook
cl = InputBox("Enter Column to Search")
st = InputBox("Enter String to Search")
l = Len(st)
nodt = Application.WorksheetFunction.CountA(w.ActiveSheet.Range(cl & ":" & cl))
For lp1 = 1 To nodt
w.ActiveSheet.Range(cl & lp1).Activate
chkst = w.ActiveSheet.Range(cl & lp1)
    If Right(chkst, l) = st Then
        Rows(lp1 & ":" & lp1).Delete Shift:=xlUp
        lp1 = lp1 - 1
    End If
    If lp1 = Application.WorksheetFunction.CountA(w.ActiveSheet.Range(cl & ":" & cl)) Then GoTo 10
Next lp1
10
End Sub

Hope this helps.... mind the spacing issue...if you find any while pasting the code in your vb editor;)
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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