delete if contains

M

Miree

I curently have this macro which works fine, I now need to adapt it for
TextBox9 and only delete line if it does not contain words typed into text
box

Sub Filter()
Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DY"), Cells(Rows.Count, "DY").End(xlUp))

With rng
For i = .Rows.Count To 1 Step -1
If Not .Cells(i) = UserForm7.ComboBox2.Value Then
.Cells(i).EntireRow.Delete
End If
Next i
End With
End Sub

Any help pwill be much appreciated
Thanks
 
J

Jacob Skaria

f Not .Cells(i) = UserForm7.TextBox9.Text Then
.Cells(i).EntireRow.Delete
End If
 
M

Miree

This only works if the contents are exact i am looking to make it work if one
word is typed in to the text box it will find it if it appears anywhere in
the cell text
 
J

Jacob Skaria

Dear Miree

User Instr function


If Instr(.Cells(i),UserForm7.TextBox9.Text) = 0 Then
.Cells(i).EntireRow.Delete
End If


If this post helps click Yes
 
M

Miree

That works perfectly thanks, i have a slightly more complicated problem along
these lines and you help would once again be much appreciated

using the same code would it be possible to delete line if value is not
equal to or inbetween text boxes 5 and 6 (box 5 always being less or the same
as 6)
 

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