Microsoft 365 Msgbox avec Conditions

eric72

XLDnaute Accro
Bonjour à tous,
J'ai un petit souci avec une msgbox, je m'explique.
A l'ouverture du fichier j'ai mis une msgbox avec conditions, cela marche bien sauf que lorsque aucune ligne n'est concernée par les conditions la msgbox apparait quand même sans contenu, savez-vous comment on peut éviter cela?
Merci à tous pour votre dévouement.
Eric
 

Pièces jointes

  • Test.xlsm
    27.7 KB · Affichages: 3
Solution
Bonjour.
Essayez comme ça :
VB:
Private Sub Workbook_Open()
   Dim LOt As ListObject, DateAlerte As Date, CCPF As Integer, CDCC As Integer, TDon(), TMsg() As String, L&, M&
   Set LOt = Feuil1.ListObjects(1)
   DateAlerte = Date - Feuil2.[C2].Value
   CCPF = LOt.ListColumns("Commande passée au Fournisseur").Index
   CDCC = LOt.ListColumns("Date Comm. Client").Index
   If LOt.ListRows.Count < 1 Then Exit Sub
   TDon = LOt.DataBodyRange.Value
   For L = 1 To UBound(TDon, 1)
      If TDon(L, CDCC) <= DateAlerte And IsEmpty(TDon(L, CCPF)) Then
         M = M + 1: ReDim Preserve TMsg(1 To M)
         TMsg(M) = TDon(L, 1) & " " & TDon(L, 2) & " " & TDon(L, 3)
         End If
      Next L
   If M > 0 Then MsgBox "Commandes non passées aux...

Dranreb

XLDnaute Barbatruc
Bonjour.
Essayez comme ça :
VB:
Private Sub Workbook_Open()
   Dim LOt As ListObject, DateAlerte As Date, CCPF As Integer, CDCC As Integer, TDon(), TMsg() As String, L&, M&
   Set LOt = Feuil1.ListObjects(1)
   DateAlerte = Date - Feuil2.[C2].Value
   CCPF = LOt.ListColumns("Commande passée au Fournisseur").Index
   CDCC = LOt.ListColumns("Date Comm. Client").Index
   If LOt.ListRows.Count < 1 Then Exit Sub
   TDon = LOt.DataBodyRange.Value
   For L = 1 To UBound(TDon, 1)
      If TDon(L, CDCC) <= DateAlerte And IsEmpty(TDon(L, CCPF)) Then
         M = M + 1: ReDim Preserve TMsg(1 To M)
         TMsg(M) = TDon(L, 1) & " " & TDon(L, 2) & " " & TDon(L, 3)
         End If
      Next L
   If M > 0 Then MsgBox "Commandes non passées aux fournisseurs :" _
      & vbLf & "— " & Join(TMsg, vbLf), vbExclamation, "Ouverture " & ThisWorkbook.Name
   End Sub
 

Statistiques des forums

Discussions
312 338
Messages
2 087 397
Membres
103 534
dernier inscrit
Kalamymustapha