Excel dynamic search vba code

Louai Al Falahi

With this VBA macro for Excel I get instant search filter when I type the whole word, but I want it as follows: when I type O for opel, that I get opel already showing.

This is the code:

Sub MG26Nov26
Private Sub TextBox1_Change()
Dim Ray As Variant
If Len(TextBox1.Value) = 0 Then
    Sheet1.AutoFilterMode = False
    Else
        If Sheet1.AutoFilterMode = True Then
            Sheet1.AutoFilterMode = False
        End If
    Ray = Split(TextBox1, "+")
    Sheet1.Range("A2:F" & Rows.Count).AutoFilter field:=1, Criteria1:=Ray, Operator:=xlFilterValues  
    End If

End Sub

This is the test file:

https://drive.google.com/open?id=1KDwE2jT_u35wPhd5dR7Xi3X31ddzXDNx

Rajesh S

To solve the issue, you can use the below written VBA code.

Private Sub TextBox1_Change()
Dim Ray As Variant
If Len(TextBox1.Value) = 0 Then
    Sheet1.AutoFilterMode = False
    Else
        If Sheet1.AutoFilterMode = True Then
            Sheet1.AutoFilterMode = False
        End If

    Sheet1.Range("A2:F" & Rows.Count).AutoFilter field:=1, Criteria1:="*" & TextBox1.Text & "*", Operator:=xlFilterValues
    End If

End Sub

N.B. This is the Change I've done in the VBA Code Criteria1:="*" & TextBox1.Text & "*" in place of the Ray variable.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related