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
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Watch MrExcel Video

Forum statistics

Threads
1,123,176
Messages
5,600,147
Members
414,365
Latest member
UUR

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
Top