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

  • Thread starter Thread starter Laura
  • Start date Start date
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
 
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
 

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