Remove rows based on any selected criteria

J

Juan

I would to remove rows containing any data type (text,
number or date) that the user choose. i create the form
where the range and the criteria can be entered, however
in the find portion if I change find(what:"0" ... it works
fine but when I change for NewTxtRem (see code below) that
comes from the user form caption TextToRemove I get
runtime error 438 Object doesn't support this property or
method in the line
Set rgFoundCell = RefEdit2.Find(What:=NewTxtRem,
LookAt:=xlWhole)

Can I get some help to how overcome this? THANKS A LOT

Private Sub go_Click()
' Perform the selected operation
Dim WorkRange As Range
Dim NewTxtRem As Variant
NewTxtRem = TextToRemove.Text

' Validate Range reference
If Not ValidReference(RefEdit2.Text) Then
MsgBox "Invalid range.", vbInformation
Application.ScreenUpdating = True
With RefEdit2
.SelStart = 0
.SelLength = 100
.SetFocus
End With
Exit Sub
End If

' Figure out what to do
Application.ScreenUpdating = False
Dim rgFoundCell As Range
Application.ScreenUpdating = False
Set rgFoundCell = RefEdit2.Find
(What:=NewTxtRem, LookAt:=xlWhole)
Do Until rgFoundCell Is Nothing
rgFoundCell.EntireRow.Delete
Set rgFoundCell = NewTxtRem.FindNext
Loop
Application.ScreenUpdating = True
Unload Me
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

Top