Find item and delete rows

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
 
R

Ron de Bruin

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
 
Top