VBA Liste & messagebox

Bonjour

j'ai un petit code pour lister des taches à faire. Est il possible de ne pas afficher la messagebox si il n'y a pas d'éléments listés ?

Voici un extrait de ce dernier

  ' ********************************* Regularisation
    For Lig = 2 To w1.Range("AU" & Rows.Count).End(xlUp).Row
        sDate = w1.Range("AW" & Lig)

             If IsDate(sDate) Then
                 LaDate = DateValue(sDate)
                 P = D - LaDate
                 If P >= 0 Then ListeRegularisation = ListeRegularisation & vbLf & "La demande de " & Cells(Lig, "AU").Value & " de " & Cells(Lig, "AU").Value & " pour " & Cells(Lig, "D").Value & " " & Cells(Lig, "C").Value & " devrait être réalisée avant le " & Cells(Lig, "AT").Value
                 If P > -30 And P < 0 Then ListeRegularisation2 = ListeRegularisation2 & vbLf & "La demande de " & Cells(Lig, "AU").Value & " pour " & Cells(Lig, "D").Value & " " & Cells(Lig, "C").Value & " devait être réalisée avant le " & Cells(Lig, "AT").Value
             End If

    Next Lig

    ' ********************************* Messagebox
    If Rep = vbCancel Then Exit Sub

    Rep = MsgBox(ListeRegularisation2, vbExclamation + vbOKCancel, "Liste des titres de séjour expirés")
    If Rep = vbCancel Then Exit Sub

    Rep = MsgBox(ListeRegularisation, vbExclamation + vbOKCancel, "Demandes de titres de séjour à faire")
    If Rep = vbCancel Then Exit Sub

Bonjour,

Un essai :

'********************************* Message box
If Len(ListeRegularisation2) > 1 Then
    Rep = MsgBox(ListeRegularisation2, vbExclamation + vbOKCancel, "Liste des titres de séjour expirés")
    If Rep = vbCancel Then Exit Sub
End If
If Len(ListeRegularisation) > 1 Then
    Rep = MsgBox(ListeRegularisation, vbExclamation + vbOKCancel, "Demandes de titres de séjour à faire")
    If Rep = vbCancel Then Exit Sub
End If

Bonjour

Rapide et efficace, merci beaucoup

Rechercher des sujets similaires à "vba liste messagebox"