Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Utilisation de Find

3 réponses
Avatar
P. de Candolle
Lorsqu'on utilise Find dans une macro Excel, il trouve un élément
contenant la recherche.
Y a-t-il un moyen qu'il trouve immédiatement la totalité de la question
et non une partie.
Exemple: Je cherche "Pierre" et il me sort "Pierrette".
J'aimerai trouver "Pierre" tout de suite.
Merci pour un tuyeau.
Pierre

3 réponses

Avatar
MichDenis
La méthode Find a des options :

En VBA, il y a le paramètre LookAt que tu dois utiliser avec la valeur XlWhole

À partir de la commande Edition / rechercher / si tu cliques sur le bouton
Options, tu peux définir le même paramètre en cochant
"totalité du contenu dans la cellule"

Je t'invite à lire fortement et plus d'une fois l'aide qu'excel a mis à
l'intention des usagers.




"P. de Candolle" a écrit dans le message de news:

Lorsqu'on utilise Find dans une macro Excel, il trouve un élément
contenant la recherche.
Y a-t-il un moyen qu'il trouve immédiatement la totalité de la question
et non une partie.
Exemple: Je cherche "Pierre" et il me sort "Pierrette".
J'aimerai trouver "Pierre" tout de suite.
Merci pour un tuyeau.
Pierre
Avatar
JB
Bonjour,


http://cjoint.com/?cnrCvHnQti

SubChercheMotEntier()
[a:a].Interior.ColorIndex = xlNone
mot = InputBox("Mot cherché? ")
If mot = "" Then Exit Sub
Set r = [a:a].Find(What:=mot, LookAt:=xlWhole)
If Not r Is Nothing Then colorie r
Set r = [a:a].Find(What:="* " & mot, LookAt:=xlWhole)
If Not r Is Nothing Then colorie r
Set r = [a:a].Find(What:=mot & " *", LookAt:=xlWhole)
If Not r Is Nothing Then colorie r
Set r = [a:a].Find(What:="* " & mot & " *", LookAt:=xlWhole)
If Not r Is Nothing Then colorie r
End Sub

Sub colorie(r)
premier = r.Address
Do
r.Interior.ColorIndex = 4
Set r = [a:a].FindNext(r)
Loop While Not r Is Nothing And r.Address <> premier
End Sub

http://boisgontierjacques.free.fr/pages_site/cellules.htm#find

JB
http://boisgontierjacques.free.fr


On 13 fév, 16:29, "P. de Candolle"
wrote:
Lorsqu'on utilise Find dans une macro Excel, il trouve un élément
contenant la recherche.
Y a-t-il un moyen qu'il trouve immédiatement la totalité de la questio n
et non une partie.
Exemple: Je cherche "Pierre" et il me sort "Pierrette".
J'aimerai trouver "Pierre" tout de suite.
Merci pour un tuyeau.
Pierre


Avatar
JB
Mot entier seulement:

Sub MotEntier()
[a:a].Interior.ColorIndex = xlNone
mot = InputBox("Mot cherché? ")
If mot = "" Then Exit Sub
Set r = [a:a].Find(What:=mot, LookAt:=xlWhole)
If Not r Is Nothing Then
premier = r.Address
Do
r.Interior.ColorIndex = 4
Set r = [a:a].FindNext(r)
Loop While Not r Is Nothing And r.Address <> premier
End If
End Sub

Mot entier dans un paragraphe:

Sub MotEntierTexte()
[a:a].Interior.ColorIndex = xlNone
mot = InputBox("Mot cherché? ")
If mot = "" Then Exit Sub
Set r = [a:a].Find(What:=mot, LookAt:=xlWhole)
If Not r Is Nothing Then colorie r
Set r = [a:a].Find(What:="* " & mot, LookAt:=xlWhole)
If Not r Is Nothing Then colorie r
Set r = [a:a].Find(What:=mot & " *", LookAt:=xlWhole)
If Not r Is Nothing Then colorie r
Set r = [a:a].Find(What:="* " & mot & " *", LookAt:=xlWhole)
If Not r Is Nothing Then colorie r
End Sub

Sub colorie(r)
premier = r.Address
Do
r.Interior.ColorIndex = 4
Set r = [a:a].FindNext(r)
Loop While Not r Is Nothing And r.Address <> premier
End Sub

JB

On 13 fév, 16:29, "P. de Candolle"
wrote:
Lorsqu'on utilise Find dans une macro Excel, il trouve un élément
contenant la recherche.
Y a-t-il un moyen qu'il trouve immédiatement la totalité de la questio n
et non une partie.
Exemple: Je cherche "Pierre" et il me sort "Pierrette".
J'aimerai trouver "Pierre" tout de suite.
Merci pour un tuyeau.
Pierre