watashi a écrit :
Salut guendalf,
j'ai eu un cas à peu près pareil. Ma sollution :
Code :
- Sub cherc()
- Dim a, b
- a = 1
- For a = 1 To 10
- If Cells(a, 1).Text = "thomas*" Then b = a: GoTo 1
- Next a
- 1 If b = "" Then MsgBox ("aucune occurrence" ) Else MsgBox ("ligne : " & b)
- End Sub
|
C'est fastidieux, c'est pas find qui est utilisé mais jusqu'à présent j'ai pas eu la chance de tomber sur une autre sollution.
Je suis aussi prenneuse si un mieux existe
|
Ah! Goto!!!! Beurk!!!!!!!!!!! lol
Mais tu m'as donne une idee
Il suffit d'utiliser Find toujours, mais en verifiant si la case qu'il nous retourne contient le bon texte. Sinon on continue la recherche.
Voici un exemple qui permet de trouver la case contenant "dog*" dans la liste de mot "A1:A10"
Code :
- Public Sub RechercheExacte()
- Dim c As Range
- Dim search_word As String
- Dim next_line As Integer
- search_word = "dog*"
- With ActiveWorkbook.Worksheets(1)
- Set c = .Range("A1:A10" ).Find(what:=search_word, LookIn:=xlValues)
- If Not c Is Nothing Then
- If c.Value <> search_word Then
- Do
- next_line = c.Row + 1
- Set c = .Range("A" & next_line & ":A10" ).Find(what:=search_word, LookIn:=xlValues)
- Loop While Not c Is Nothing And next_line <= 10 And c.Value <> search_word
- End If
- If c.Value = search_word Then
- MsgBox "Found in " & c.Address, vbInformation
- Else
- MsgBox "Not found.", vbInformation
- End If
- Else
- MsgBox "Not found", vbInformation
- End If
- End With
- End Sub
|
P.S: J'aurai pu utiliser FindNext dans le bout de code precedent, mais j'ai remarque que le resultat etait incorrect avec FindNext si j'avais un appel de fonction entre le premier Find et le FindNext... et je n'ai pas encore compris pk ce n'etait pas possible (d'ou mon vieux hack pourri pour rechercher l'element suivant en reduisant la taille du Range). Mais je vous accorde qu'ici, n'ayant aucun appel de fonction, FindNext aurait tres bien fonctionne. (Au moins j'ai pu poser ma question sur FindNext qui me tarode depuis un ptit bout de tps maintenant...)
Bonne soiree a ceux qui ont pris le tps de tout lire
---------------
Guendalf