Textbox with multiple search records

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have a textbox3 and all the name records in sheet1. I am not sure as once the user enters a name in the textbox3, then code should search the all the results and should display with multiple records.

eg:-
sheet1 column C have names as
X
Xy
XXy
AA
AB
ADS
CC

if user enters as "X" in textbox3 then all the records related to it should be displayed "X,Xy,XXY" and user can select any one of the record.

Any idea
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this:
This script will run when you click on a button after entering search value in textbox3

Code:
Sub Filter_Me_Please()
'Modified 7/2/18 6:45 AM EDT
Dim Lastrow As Long
Dim c As Long
Dim s As Variant
Dim ans As String
ans = ActiveSheet.TextBox3.Value
c = "3" ' Column Number Modify this to your need
s = ans & "*" 'Saerch Value Modify to your need
Lastrow = Cells(Rows.Count, c).End(xlUp).Row
With ActiveSheet.Cells(1, c).Resize(Lastrow)
    .AutoFilter 1, s
    counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
    If counter > 1 Then
       
    Else
        MsgBox "No values found"
        .AutoFilter
    End If
    
End With
End Sub
 
Last edited:
Upvote 0
textbox3 is on userform1



Try this:
This script will run when you click on a button after entering search value in textbox3

Code:
Sub Filter_Me_Please()
'Modified 7/2/18 6:45 AM EDT
Dim Lastrow As Long
Dim c As Long
Dim s As Variant
Dim ans As String
ans = ActiveSheet.TextBox3.Value
c = "3" ' Column Number Modify this to your need
s = ans & "*" 'Saerch Value Modify to your need
Lastrow = Cells(Rows.Count, c).End(xlUp).Row
With ActiveSheet.Cells(1, c).Resize(Lastrow)
    .AutoFilter 1, s
    counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
    If counter > 1 Then
       
    Else
        MsgBox "No values found"
        .AutoFilter
    End If
    
End With
End Sub
 
Upvote 0
Dim c As Long
Dim s As Variant
Dim ans As String
ans = ActiveSheet.TextBox3.Value
c = "3" ' Column Number Modify this to your need
Curious to understand, in the suggested code, why declare a long variable but pass a string to it yet refer to it as a number? Surely it should just be c = 3?

I believe the complier is able to convert "3" to 3, but it seems an unnecessary extra step. Should c be declared as a string or only have a number passed to it, when declared as long? With other data types, when I've passed the wrong value to type it throws an error when the code runs of mis-match data types.

Also, the two arguments to Cells(x, y) are of type long, so although c is declared as long, why also pass in a string of "3"?
 
Last edited:
Upvote 0
Yes scrips runs well, but I don't want the autofilter, what I need is the relative names to be displayed and the user can select the desired name.
Once the user enters a text in the me.textbox3. then it should search all the relative names and should display the same.
 
Last edited:
Upvote 0
You said:
I need is the relative names to be displayed and the user can select the desired name.

How do you want the relative names displayed.

I know of no way for all the relative names to be displayed in a TextBox
To have the user select from a list of relative names he would need to select from a Combobox.

And I know of no way to just display the information without AutoFilter.

But maybe someone else here at Mr. Excel has an answer.
 
Upvote 0
Ok,
relative name should be dispalyed as bubbol help to the user and user can select the correct name

I mean in excel we have Alt+down arrow then we have a list to view and select.
Same way if the user enter first 2 words in the me.textbox3 then there it will display by itself and user select the right word. I hope I am clear now.
 
Upvote 0
You said:
should be dispalyed as bubbol help

I do not know what
bubbol help
is?

You said:
Same way if the user enter first 2 words in the me.textbox3

A textbox cannot display a list of names to choose from at least if it can I do not know how to do that.

This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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