Find item and delete rows

  • Thread starter Thread starter Joseph
  • Start date Start date
J

Joseph

VBA help needed for a beginner.

I need to find a first instance of a string in first column and then
to delete all the rows from the one in which the string was found to
the end of the spreadsheet.

Thanks,

Joseph
 
Hi Joseph

Try this example for column A

Sub Find_First()
Dim FindString As String
Dim Rng As Range
FindString = InputBox("Enter a Search value")
If Trim(FindString) <> "" Then
Set Rng = Range("A:A").Find(What:=FindString, _
After:=Range("A" & Rows.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then Rows(Rng.Row & ":" & Rows.Count).Delete
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top