Samadhan Gaikwad
Member
Hi All,
I have below code (from Youtube: Dynamic filters in Excel (Filter as you type) - Excel VBA Tutorial) for filtering columns according to text from header/textbox as one type. But getting runtime error 1004.
I want:
1. To fix the existing error.
2. To apply the filters using criteria in one column or more than one (i.e. when user gives input in more than one textbox).
3. To know is this method OK as user types vba starts running, filter gets applied or another approach as soon as user hit button after adding text in textbox, filter will be applied.
I have below code (from Youtube: Dynamic filters in Excel (Filter as you type) - Excel VBA Tutorial) for filtering columns according to text from header/textbox as one type. But getting runtime error 1004.
I want:
1. To fix the existing error.
2. To apply the filters using criteria in one column or more than one (i.e. when user gives input in more than one textbox).
3. To know is this method OK as user types vba starts running, filter gets applied or another approach as soon as user hit button after adding text in textbox, filter will be applied.
Code:
Private Sub TextBox1_Change()
If Len(TextBox1.Value) = 0 Then
Sheet1.AutoFilterMode = False
Else
If Sheet1.AutoFilterMode = True Then
Sheet1.AutoFilterMode = False
End If
'Sheet1.Range("A2:B" & Rows.Count).AutoFilter field:=1, Criteria1:="*" & TextBox1.Value & "*"
Sheet1.Range("A2:B100").AutoFilter field:=1, Criteria1:="*" & TextBox1.Value & "*"
End If
End Sub
Private Sub TextBox2_Change()
If Len(TextBox2.Value) = 0 Then
Sheet1.AutoFilterMode = False
Else
If Sheet1.AutoFilterMode = True Then
Sheet1.AutoFilterMode = False
End If
'Sheet1.Range("A2:B" & Rows.Count).AutoFilter field:=2, Criteria1:="*" & TextBox2.Value & "*"
Sheet1.Range("A2:B100").AutoFilter field:=2, Criteria1:="*" & TextBox2.Value & "*"
End If
End Sub
Attachments
Last edited: