Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

Autres ajouter un msgbox si la recherche est faux mrci pour aide

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

issam salem

XLDnaute Junior
With ThisWorkbook.Sheets("Inventaire")
For Each Nom In .Range("L4:L" & .[L65000].End(xlUp).Row)
If CStr(Nom) = CStr(Me.Ithemmag.Value) And .Cells(Nom.Row, 1) = Me.TextBox1.Text Then
Me.Ithemcate.Caption = .Cells(Nom.Row, 2)
Me.Ithemstock.Caption = .Cells(Nom.Row, 4)
Me.Ithemdes.Caption = .Cells(Nom.Row, 6)
Me.Ithemref.Caption = .Cells(Nom.Row, 7)
Me.Ithemuni.Caption = .Cells(Nom.Row, 8)
End If
Next
End With
 

Pièces jointes

  • Capture.PNG recherche.PNG
    27.3 KB · Affichages: 13
Solution
Essayez ça :
VB:
flag = 0
With ThisWorkbook.Sheets("Inventaire")
    For Each Nom In .Range("L4:L" & .[L65000].End(xlUp).Row)
        If CStr(Nom) = CStr(Me.Ithemmag.Value) And .Cells(Nom.Row, 1) = Me.TextBox1.Text Then
            Me.Ithemcate.Caption = .Cells(Nom.Row, 2)
            Me.Ithemstock.Caption = .Cells(Nom.Row, 4)
            Me.Ithemdes.Caption = .Cells(Nom.Row, 6)
            Me.Ithemref.Caption = .Cells(Nom.Row, 7)
            Me.Ithemuni.Caption = .Cells(Nom.Row, 8)
            flag = 1
        End If
    Next
    If flag = 0 Then
        MsgBox "Ce code article n'existe pas.dans le magasin.Veuillez saisir un code article valide", vbInformation + vbOKOnly, "Article non trouvé"
        Me.Ithemcate.Caption = ""...
Tout d'abord Bonjour Issam Salem,
Ensuite prenez l'habitude d'utiliser la balise </> pour le code, c'est plus lisible.
Pour le code utilisez l'indentation, là aussi c'est plus lisible.
Enfin je suppose que le Msgbox dois être émis dans le cas où le IF est faux. Dans ce cas :
Code:
With ThisWorkbook.Sheets("Inventaire")
    For Each Nom In .Range("L4:L" & .[L65000].End(xlUp).Row)
        If CStr(Nom) = CStr(Me.Ithemmag.Value) And .Cells(Nom.Row, 1) = Me.TextBox1.Text Then
            Me.Ithemcate.Caption = .Cells(Nom.Row, 2)
            Me.Ithemstock.Caption = .Cells(Nom.Row, 4)
            Me.Ithemdes.Caption = .Cells(Nom.Row, 6)
            Me.Ithemref.Caption = .Cells(Nom.Row, 7)
            Me.Ithemuni.Caption = .Cells(Nom.Row, 8)
        Else
            MsgBox "Désolé, pas trouvé !"
        End If
    Next
End With
 
Tout d'abord Re Bonsoir Issam Salem,

D'où ma question :
je suppose que le Msgbox dois être émis dans le cas où le IF est faux
Si vous ne voulez qu'un Msgbox une fois tous les For exécuté, alors il faut créer une variable Flag.
Au départ elle vaut 0. Si on passe dans un IF ok, on la met à 1.
En sortant si ce flag vaut 1 on fait le msgbox.
VB:
Sub rt()
Flag = 0
With ThisWorkbook.Sheets("Inventaire")
    For Each Nom In .Range("L4:L" & .[L65000].End(xlUp).Row)
        If CStr(Nom) = CStr(Me.Ithemmag.Value) And .Cells(Nom.Row, 1) = Me.TextBox1.Text Then
            Me.Ithemcate.Caption = .Cells(Nom.Row, 2)
            Me.Ithemstock.Caption = .Cells(Nom.Row, 4)
            Me.Ithemdes.Caption = .Cells(Nom.Row, 6)
            Me.Ithemref.Caption = .Cells(Nom.Row, 7)
            Me.Ithemuni.Caption = .Cells(Nom.Row, 8)
            Flag = 1
        End If
    Next
    If Flag = 1 Then MsgBox "Désolé, pas trouvé !"
End With
End Sub
 
merci ca marche juste je Jai changé le flag=0 sur if .
j ajoute le code pour vider les labels après if ms sa fonctionne pas :

Flag = 0
With ThisWorkbook.Sheets("Inventaire")
For Each Nom In .Range("L4:L" & .[L65000].End(xlUp).Row)
If CStr(Nom) = CStr(Me.Ithemmag.Value) And .Cells(Nom.Row, 1) = Me.TextBox1.Text Then
Me.Ithemcate.Caption = .Cells(Nom.Row, 2)
Me.Ithemstock.Caption = .Cells(Nom.Row, 4)
Me.Ithemdes.Caption = .Cells(Nom.Row, 6)
Me.Ithemref.Caption = .Cells(Nom.Row, 7)
Me.Ithemuni.Caption = .Cells(Nom.Row, 8)
Flag = 1
End If
Next
If Flag = 0 Then MsgBox "Ce code article n'existe pas.dans le magasin.Veuillez saisir un code article valide", vbInformation + vbOKOnly, "Article non trouvé"
Me.Ithemcate.Caption = ""
Me.Ithemstock.Caption = ""
Me.Ithemdes.Caption = ""
Me.Ithemref.Caption = ""
Me.Ithemuni.Caption = ""
Exit Sub
End With
 
Re Bonsoir,
sa fonctionne pas :
Qu'est ce qui ne fonctionne pas ? Le Msgbox, le vidage ?

Ensuite prenez l'habitude d'utiliser la balise </> pour le code, c'est plus lisible.
Pour le code utilisez l'indentation, là aussi c'est plus lisible.
Ca fait trois fois que je copie colle ce code en vrac pour essayé de comprendre ce que vous voulez faire. Faites un effort.
Je vous souhaite un excellente soirée.
 
Essayez ça :
VB:
flag = 0
With ThisWorkbook.Sheets("Inventaire")
    For Each Nom In .Range("L4:L" & .[L65000].End(xlUp).Row)
        If CStr(Nom) = CStr(Me.Ithemmag.Value) And .Cells(Nom.Row, 1) = Me.TextBox1.Text Then
            Me.Ithemcate.Caption = .Cells(Nom.Row, 2)
            Me.Ithemstock.Caption = .Cells(Nom.Row, 4)
            Me.Ithemdes.Caption = .Cells(Nom.Row, 6)
            Me.Ithemref.Caption = .Cells(Nom.Row, 7)
            Me.Ithemuni.Caption = .Cells(Nom.Row, 8)
            flag = 1
        End If
    Next
    If flag = 0 Then
        MsgBox "Ce code article n'existe pas.dans le magasin.Veuillez saisir un code article valide", vbInformation + vbOKOnly, "Article non trouvé"
        Me.Ithemcate.Caption = ""
        Me.Ithemstock.Caption = ""
        Me.Ithemdes.Caption = ""
        Me.Ithemref.Caption = ""
        Me.Ithemuni.Caption = ""
        Exit Sub
    End If
End With
 
Merci sylvanu

ca marche bien
alors mon projet c'est une application de gestion du stock
Jai le tableau inventaire 'image1'. sur l userform d'image 2 je veux consulter le stock d'article "code article par magasin 'dernier ligne'" sachant qu'il est possible de trouver le même code sur le tableau ms de magasin différents.
 

Pièces jointes

  • Capture.PNG inventaire.PNG
    73.2 KB · Affichages: 11
  • Capture.PNG recherche.PNG
    27.3 KB · Affichages: 11
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
10
Affichages
1 K
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…