deleting rows that are not equal to a value entered from an input box, Please Help Me

L

Laura

Hi

I'm trying to make an excel document that, when you open it, it pops
up an Input box. It will ask you for a number. Then once you hit
enter it will search the first sheet in the first column and if the
value is different then the one that you put in the input box it will
delete the entire row.

Thank you so much
Laura
 
R

Ron de Bruin

Try this one Laura
A1 must have a header

Sub Delete_with_Autofilter()
Dim FindString As String
Dim rng As Range

FindString = InputBox("Enter your Findstring")
If Trim(FindString) <> "" Then

With ActiveSheet
.Columns("A").AutoFilter Field:=1, Criteria1:="<>" & FindString
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete

End With
.AutoFilterMode = False
End With
End If
End Sub
 
Top