Next sans for
Résolu
Theyoshi
-
M-12 Messages postés 1332 Date d'inscription Statut Membre Dernière intervention -
M-12 Messages postés 1332 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Ce code ne fonctionne pas, il m'indique un next sans for en fin de code. Avez vous des idées ?
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
A voir également:
- Next sans for
- Downloader for pc - Télécharger - Téléchargement & Transfert
- Idm for mac - Télécharger - Téléchargement & Transfert
- Copytrans heic for windows - Télécharger - Visionnage & Diaporama
- Instagram for pc - Télécharger - Divers Communication
- Microsoft store download for pc - Guide
2 réponses
Bonjour
Teste plutôt comme ceci
Tu avais des End If ainsi que le Next à la fin inutiles
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
Bonjour,
L'indentation du code permet d'éviter ce type d'erreur, voir :
https://silkyroad.developpez.com/VBA/DebuterMacros/#LV
L'indentation du code permet d'éviter ce type d'erreur, voir :
https://silkyroad.developpez.com/VBA/DebuterMacros/#LV
La colonne "AU" est bien au format date. Il n'y a pas de différences notables avec la première partie du programme
Sans voir ce qu'il y a dans le classeur ???
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/
Voici donc le lien : https://www.cjoint.com/c/JDshOtFILth