Re : Modification Macro

Publié par BrunoM45 le 25/11/2013 23:02:00
Bonjour Ntx et bienvenue sur ce forum

Tu peux essayer ce code
Private Sub Workbook_Open()
  
Dim DLig As LongLig As Long
  Dim sTmp 
As StringsDate As StringvDate As Date
  Dim EcartJ 
As LongEcartM As Long
  Dim Msg 
As String
  With Worksheets
("Model 1")
    
DLig = .Range("B" Rows.Count).End(xlUp).Row
    
For Lig 13 To DLig  ' Pour chaque ligne
      sTmp = .Range("B" & Lig).Value
      ' 
Vérifier s'il s'agit d'une ligne d'ouverture
      
' Sinon, passer à la ligne suivante
      If InStr(1, sTmp, "Date ouv") = 0 Then GoTo SuiteLig
      ' 
Récupérer le texte de la date
      sDate 
Mid(sTmpInStr(1sTmp"/") - 210)
      
' Convertir en valeur de date
      vDate = DateValue(sDate)
      ' 
Calculer l'écart en mois
      EcartM = DateDiff("m", vDate, Now)
      ' 
Selon l'écart
      If EcartM >= 2 And EcartM < 3 Then
        EcartJ = DateDiff("d", vDate, Now)
        Msg = Msg & "Le client  " & .Cells(Lig - 2, 2) & " pour " _
            & ", N°Reg " & .Cells(Lig - 3, 4) & "  atteint  ces 3 mois, dans " & EcartJ & " jours." & Chr(10)
      ElseIf EcartM > 3 Then
        Msg = Msg & "Le client " & .Cells(Lig - 2, 2) & " pour " _
            & ", mat " & .Cells(Lig, 1) & " a dejà atteint  3 mois et  plus  " & Chr(10)
      End If
SuiteLig:
    Next Lig
    MsgBox Msg
  End With
End Sub


A+

Ce message est de : http://excel.veriti.net/modules/newbb/viewtopic.php?post_id=276