VBA - Userform using "contains" or Wildcards to filter

JLH01

New Member
Joined
Jul 17, 2014
Messages
1
Hi all

Need a little help here. I have been searching multiple forums and I have not found a solution that works for the code I have. I am a noob...FYI

So my issue is this. I think I actually have the correct code. My userform will filter on all of the criteria except for the two columns that have Date/Time (which is derived from msg.SentOn and msg.ReceivedTime). All of the other columns that the textboxes are associated with are all text (no numbers or special characters). So I am not sure why the form searches and filters everything else.

With ActiveSheet
.AutoFilterMode = False
With .Range("B2")
.AutoFilter
If Len(Me.TextBox1.Value) > 0 Then
.AutoFilter Field:=2, Criteria1:="*" & Me.TextBox1.Value & "*", Operator:=xlAnd
End If

If Len(Me.TextBox2.Value) > 0 Then
.AutoFilter Field:=3, Criteria1:="*" & Me.TextBox2.Value & "*", Operator:=xlAnd
End If

If Len(Me.TextBox3.Value) > 0 Then
.AutoFilter Field:=4, Criteria1:="*" & Me.TextBox3.Value & "*", Operator:=xlAnd
End If

If Len(Me.TextBox4.Value) > 0 Then
.AutoFilter Field:=5, Criteria1:="*" & Me.TextBox4.Value & "*", Operator:=xlAnd
End If

If Len(Me.TextBox8.Text) > 0 Then
.AutoFilter Field:=6, Criteria1:="*" & Me.TextBox8.Value & "*", Operator:=xlAnd
End If

If Len(Me.TextBox6.Value) > 0 Then
.AutoFilter Field:=7, Criteria1:="*" & Me.TextBox6.Value & "*", Operator:=xlAnd
End If

If Len(Me.TextBox7.Value) > 0 Then
.AutoFilter Field:=8, Criteria1:="*" & Me.TextBox7.Value & "*", Operator:=xlAnd
End If

End With
End With

End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top