Next sans for

Résolu
Theyoshi -  
M-12 Messages postés 1349 Statut Membre -
Bonjour,

Ce code ne fonctionne pas, il m'indique un next sans for en fin de code. Avez vous des idées ?

Sub alerte()

Dim w1 As Worksheet
Dim i As Long
Dim D As Date
Dim j As Integer
Dim Liste As String

Set w1 = Worksheets("Effectif") 'Feuille qui contient les alertes
D = Date

' ********************************* fin de CMU
For i = 4 To w1.Range("Y" & Rows.Count).End(xlUp).Row
ladate = w1.Range("Y" & i)
If ladate <> "" Then
p = D - ladate
If p >= 0 Then Liste = Liste & vbLf & Cells(i, "C").Value & " a déja expiré depuis le " & Cells(i, "Y")
End If
If p > -30 And p < 0 Then Liste = Liste & vbLf & "La CMU pour " & Cells(i, "C").Value & " expirera le " & Cells(i, "Y").Value
End If
End If
Next i

' ********************************* fin d'ATJM
For i = 4 To w1.Range("T" & Rows.Count).End(xlUp).Row
ladate = w1.Range("T" & i)
If ladate <> "" Then
p = D - ladate
If p >= 0 Then Liste = Liste & vbLf & "L'ATJM pour " & Cells(i, "C").Value & " a déja expiré depuis le " & Cells(i, "T").Value
End If
If p > -30 And p < 0 Then Liste = Liste & vbLf & "L'ATJM pour " & Cells(i, "C").Value & " expirera le " & Cells(i, "T").Value
End If
End If
Next i

' ********************************* Fin d'autorisation de travail
For i = 4 To w1.Range("AU" & Rows.Count).End(xlUp).Row
ladate = w1.Range("AU" & i)
If ladate <> "" Then
p = D - ladate
If p >= 0 Then Liste = Liste & vbLf & "L'autorisation de travail pour " & Cells(i, "C").Value & " a déja expiré depuis le " & Cells(i, "AU").Value
End If
If p > -30 And p < 0 Then Liste = Liste & vbLf & "L'autorisation de travail pour " & Cells(i, "C").Value & " expirera le " & Cells(i, "AU").Value
End If
End If
Next i

Next

MsgBox Liste, vbOKOnly + vbInformation, "Alertes"

End Sub



Configuration: Windows / Chrome 81.0.4044.113

2 réponses

  1. M-12 Messages postés 1349 Statut Membre 285
     
    Bonjour
    Teste plutôt comme ceci
    Tu avais des End If ainsi que le Next à la fin inutiles

    Sub alerte()
    
    Dim w1 As Worksheet
    Dim i As Long
    Dim D As Date
    Dim j As Integer
    Dim Liste As String
    
    Set w1 = Worksheets("Effectif") 'Feuille qui contient les alertes
    D = Date
    
    
    ' ********************************* fin de CMU
      For i = 4 To w1.Range("Y" & Rows.Count).End(xlUp).Row
      ladate = w1.Range("Y" & i)
        If ladate <> "" Then
          p = D - ladate
          If p >= 0 Then Liste = Liste & vbLf & Cells(i, "C").Value & " a déja expiré depuis le " & Cells(i, "Y")
          If p > -30 And p < 0 Then Liste = Liste & vbLf & "La CMU pour " & Cells(i, "C").Value & " expirera le " & Cells(i, "Y").Value
        End If
      Next i
    
    ' ********************************* fin d'ATJM
      For i = 4 To w1.Range("T" & Rows.Count).End(xlUp).Row
        ladate = w1.Range("T" & i)
        If ladate <> "" Then
          p = D - ladate
          If p >= 0 Then Liste = Liste & vbLf & "L'ATJM pour " & Cells(i, "C").Value & " a déja expiré depuis le " & Cells(i, "T").Value
          If p > -30 And p < 0 Then Liste = Liste & vbLf & "L'ATJM pour " & Cells(i, "C").Value & " expirera le " & Cells(i, "T").Value
        End If
      Next i
    
    ' ********************************* Fin d'autorisation de travail
      For i = 4 To w1.Range("AU" & Rows.Count).End(xlUp).Row
      ladate = w1.Range("AU" & i)
        If ladate <> "" Then
          p = D - ladate
          If p >= 0 Then Liste = Liste & vbLf & "L'autorisation de travail pour " & Cells(i, "C").Value & " a déja expiré depuis le " & Cells(i, "AU").Value
          If p > -30 And p < 0 Then Liste = Liste & vbLf & "L'autorisation de travail pour " & Cells(i, "C").Value & " expirera le " & Cells(i, "AU").Value
        End If
      Next i
    
    MsgBox Liste, vbOKOnly + vbInformation, "Alertes"
    
    End Sub
    
    0
    1. Theyoshi
       
      Merci de ton aide. Mais du coup, un autre problème de type incompatibilité de type 13 pour le dernier p = D - ladate

      La colonne "AU" est bien au format date. Il n'y a pas de différences notables avec la première partie du programme
      0
    2. M-12 Messages postés 1349 Statut Membre 285 > Theyoshi
       
      Re,
      Sans voir ce qu'il y a dans le classeur ???
      0
    3. theyoshi Messages postés 10 Statut Membre > M-12 Messages postés 1349 Statut Membre
       
      Comment insérer un fichier dans ce forum ?
      0
    4. M-12 Messages postés 1349 Statut Membre 285 > theyoshi Messages postés 10 Statut Membre
       
      Re,

      Allez dans https://www.cjoint.com/
      Cliquez sur "PARCOURIR" pour sélectionner le classeur
      Clic le bouton "CREER LE LIEN"
      Clic droit quand le lien est créé "COPIER LE LIEN"
      Sur le post Clic droit "Coller".

      ou dans https://mon-partage.fr/
      0
    5. theyoshi Messages postés 10 Statut Membre > M-12 Messages postés 1349 Statut Membre
       
      Merci, je ne connaissais pas ce principe.

      Voici donc le lien : https://www.cjoint.com/c/JDshOtFILth
      0