Vba, recherche dans liste

deudecos

XLDnaute Impliqué
Bonjour a toutes et a tous,

Bon, je sais faire un truc du genre :

Dim i As Integer
For i = 2 to 200
If sheets('feuil3').Range('A' & i) = Userform1.TextBox1 then
sheets('feuil3').Range('B2') = 1
end if
next

Mais voila, moi ce que je souhaite, c'est faire le contraire, a savoir :

If Sheets('feuil3').Range('A' & i)<> userform1.TextBox1 Then
msgbox'cette entree n'est pas prise en compte'
Exit sub

Le truc, c'est que si je fais ca le message va apparaitre systematiquement a chaque ligne du moment qu'il ne trouve pas...
Ce que je voudrais moi, c'est qu'il me previenne uniquement a la fin

QQ peut il ou elle m'aider ?

Bonne journee

Olivier
 
R

Roro34

Guest
Bonjour Olivier,
Si j'ai bien compris tu veux connaitre la non existance d'un texte dans un cellule donnée.
Pour faire cela tu peux faire ca:
Dim strText As String
Dim strCell As String
Dim fFound As Boolean
Dim i As Integer
strText = Userform1.TextBox1
fFound = False
For i = 2 to 200
strCell = sheets('feuil3').Range('A' & i)
If strCell = strText then
'La valeur existe
fFound = True
sheets('feuil3').Range('B2') = 1
end if
next
If fFound = False Then
msgbox'cette entree n'est pas prise en compte'
End If

@+
 

Discussions similaires

Réponses
4
Affichages
233

Statistiques des forums

Discussions
312 485
Messages
2 088 802
Membres
103 971
dernier inscrit
abdazee