View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Greg Greg is offline
external usenet poster
 
Posts: 331
Default Deleting specific rows with a specific criteria using inputbox

Hi All,
I am trying to build a macro which would establish a range and criteria to
selec certain rows to delete. I have it partially working, but cant get past
this point. Can someone please show me the error of my ways! The code is
listed below, and I am sure I do not need most of it. greatly appreciate any
assistance.

Sub DeleteRows()
Dim r As Integer
Dim totalR As Integer
Dim question1 As String
Dim question2 As String
Dim question3 As String
Dim mySearch As String
Dim cell3 As Variant
Dim BadWord As Range
Dim cell1 As Range
Dim cell2 As Range
Dim cell4 As Range
Dim allCells As Range
totalR = Selection.Rows.Count
question1 = "What cell would you like to start with?"
question2 = "What what cell would you like to end with?"
question3 = "Please enter search word."
mySearch = cell3
Set cell1 = Application.InputBox(prompt:=question1, _
Title:="Range to Search", Type:=8)
Set cell2 = Application.InputBox(prompt:=question2, _
Title:="Range to Search", Type:=8)
cell1.Value = cell1.Value
cell3 = InputBox(prompt:=question3, _
Title:="Search word or phrase")
Set allCells = Range(cell1, cell2)
allCells.Value = allCells.Value
For Each cell1 In allCells
If allCells.Value < cell3.Value Then
ActiveCell.EntireRow.Select
Selection.EntireRow.Delete
End If
Next
end sub