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

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
    Capture.PNG recherche.PNG
    27.3 KB · Affichages: 9
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 = ""...

sylvanu

XLDnaute Barbatruc
Supporter XLD
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
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
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
 

issam salem

XLDnaute Junior
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
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
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.
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
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
 

issam salem

XLDnaute Junior
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
    Capture.PNG inventaire.PNG
    73.2 KB · Affichages: 7
  • Capture.PNG recherche.PNG
    Capture.PNG recherche.PNG
    27.3 KB · Affichages: 7

Discussions similaires

Réponses
5
Affichages
871

Statistiques des forums

Discussions
311 720
Messages
2 081 899
Membres
101 834
dernier inscrit
Jeremy06510