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

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Have you looked at slicers?

If you select the table and go to 'Table Design' in the ribbon - you will find the option to 'Insert Slicer' - it seems like they will do what you need.
 
Upvote 0
not after slicers, too many variables. Its a really big spreadsheet thousands of rows, lots of columns, I need a better solution than one user putting on a filter and then the next user coming along and going through each column to find where the filter is to unfilter to then add another filter for what they are looking for.

So was thinking a text box search and filter at the top of the page in cell a1 where it's visible to all users whats been searched for and deleting that text in the box will return all rows and columns
 
Upvote 0
I need a better solution than one user putting on a filter and then the next user coming along and going through each column to find where the filter is to unfilter to then add another filter for what they are looking for.
Not sure what this means as the filter can be removed from within the slicer itself, you would not have to look for it in the headers. If you are not after a slicer though thats fair enough as i do get the "too many variables" part.
 
Upvote 0
Do you want to search in only 1 specific column or in any column of your choice?
any column that's the bit i'm getting stuck at

this works for just column A but I can't get it to work for the other columns

Private Sub TextBox1_Change()

Dim filterValue As String

filterValue = TextBox1.Value

With Range("A3:I1003")

.AutoFilter Field:=1, Criteria1:="=*" & filterValue & "*"

End With

End Sub
 
Upvote 0
any column that's the bit i'm getting stuck at

this works for just column A but I can't get it to work for the other columns

Are you saying you need to filter just 1 column & using1 criteria at a time but which column is a variable?
 
Upvote 0
Book4
ABCDEFGHI
1
2
3ProjectProject StProject OwnerProject ScoopeProject StartImplementation DateUpdateUpdate DetailsUpdated
4A1ONEName 1SCOPE 11/1/2023YesUpdates notes 16/2/2023
5AAATWOName 2SCOPE 21/1/2023YesUpdates notes 26/3/2023
6CCCThreeName 3SCOPE 31/1/2023NoUpdates notes 36/4/2023
7A1ONEName 1SCOPE 11/1/2023YesUpdates notes 16/2/2023
Sheet1
Cell Formulas
RangeFormula
I4,I7I4=TODAY()
I5I5=TODAY()+1
I6I6=TODAY()+2


While waiting for other gurus, will share my thought here.

After input textbox need to press f4 to run the code

VBA Code:
Option Compare Text

Private Sub TextBox1_DropButtonClick()
Dim filterValue As String
On Error Resume Next

filterValue = TextBox1.Value

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 Field:=k, Criteria1:="=*" & filterValue & "*"
    End If

End With

End Sub
 
Last edited:
Upvote 0
Are you saying you need to filter just 1 column & using1 criteria at a time but which column is a variable?
Hi -the data set isn't the best example.

But the word "Akuini" could appear in cell a3 or b17, or c58, or d900, or e1000 etc

So ultimately i'd like the textbox to filter out all rows except row 3, 17, 58, 900, 1000 cos they have the "Akuini" word matches
 
Upvote 0
While waiting for other gurus, will share my thought here.

After input textbox need to press f4 to run the code

VBA Code:
Option Compare Text

Private Sub TextBox1_DropButtonClick()
Dim filterValue As String
On Error Resume Next

filterValue = TextBox1.Value

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 Field:=k, Criteria1:="=*" & filterValue & "*"
    End If

End With

End Sub
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
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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