Search Textbox Value in a Column (Excel)

Solved
benji2031 Posted messages 3 Status Member -  
benji2031 Posted messages 3 Status Member -
Bonjour,
On a plusieurs feuilles dans un classeur, dont une contenant des ingrédients.
Je souhaite créer un bouton de recherche (sur une feuille différente de la feuille des ingrédients) qui ouvre un formulaire (userform) de recherche (jusque-là, rien de complexe).

Dans ce formulaire, j'ai une textbox et un bouton "rechercher".
J'aimerais que lorsque je tape un mot dans la textbox et que je clique sur "rechercher", la macro me dirige vers la feuille des ingrédients et sélectionne la ligne correspondant à ce mot.

Exemple : je tape "chocolat" ---> rechercher et je me retrouve sur la cellule "chocolat" dans la feuille des ingrédients.
En espérant avoir été clair et concis.
Merci d'avance
Benji2031

3 answers

gbinforme Posted messages 14930 Registration date   Status Contributor Last intervention   4 744
 
Hello,

As you seem to know VBA, your task is not complicated; you just need to use the "range.find" function, which is explained in the help section.
--
Always calm
Perfection is attained not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupéry
0
benji2031 Posted messages 3 Status Member
 
Hello
I'm sorry but I know absolutely nothing about pure VBA coding, it's like starting from scratch.
I couldn't manage with the range.find function or I didn't understand how to use it.
Thank you in advance
Benji2031
0
gbinforme Posted messages 14930 Registration date   Status Contributor Last intervention   4 744
 
Hello,

I had been presumptuous to let you manage on your own; it should look like this:
Private Sub CommandButton1_Click() Dim sel As Range Set sel = Sheets("ingredients").Cells.Find(Me.TextBox1.Value, , xlValues, xlWhole) If sel Is Nothing Then MsgBox "Search not found" Else Sheets("ingredients").Activate sel.Activate End If End Sub 

Of course, you need to put your actual sheet name and your actual form control names.
--
Always zen
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupéry
0
benji2031 Posted messages 3 Status Member
 
Thank you very much for taking the time to do this!
It works perfectly!
You are the best!
0