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
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