VBA for a type as you search text box on a multi column table

Liverlee

Board Regular
Joined
Nov 8, 2018
Messages
73
Office Version
  1. 2019
Platform
  1. Windows
Hello All.

Hoping you can help me out with a VBA code. I've got a table called 'data' from a3:i1000. A3 to I3 is the header row. I've added a text box linked to cell A1. When a user enters any text value in the text box, I'm hoping the table will auto-filter to rows with that specific keyword match. So for example, if someone typed yes into the text box - then rows 4/5/7/8 would show and the other rows would be filtered out. And then when the text is cleared from the text box, all the other results reappear.
Can anyone provide a code or point me where I can find out how to do this?
 

Attachments

  • 1 mrexcel.png
    1 mrexcel.png
    31.4 KB · Views: 28
that's the closest i'm come to solving this so far :biggrin: (y) only issue is when i delete the text i still have to manually unfilter but many many thanks for helping

Using change method (FYR)

VBA Code:
Option Compare Text
Private Sub TextBox1_change()
Dim filtervalue As String
On Error Resume Next

filtervalue = TextBox1.Value

If filtervalue = "" Then
Range("a3").AutoFilter
Exit Sub
End If

With Range("A3:I" & Cells(Rows.Count, "A").End(xlUp).Row)

    k = .Find(filtervalue, lookat:=xlWhole).Column
    If CInt(k) = 0 Then
        Range("a3").AutoFilter
    Else
        .AutoFilter k, "=" & filtervalue
    End If

End With
End Sub
 
Upvote 0
Solution

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Using change method (FYR)

VBA Code:
Option Compare Text
Private Sub TextBox1_change()
Dim filtervalue As String
On Error Resume Next

filtervalue = TextBox1.Value

If filtervalue = "" Then
Range("a3").AutoFilter
Exit Sub
End If

With Range("A3:I" & Cells(Rows.Count, "A").End(xlUp).Row)

    k = .Find(filtervalue, lookat:=xlWhole).Column
    If CInt(k) = 0 Then
        Range("a3").AutoFilter
    Else
        .AutoFilter k, "=" & filtervalue
    End If

End With
End Sub
You legend - thankyou works perfectly
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

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