Next sans for

Résolu/Fermé
Theyoshi - 18 avril 2020 à 08:54
M-12 Messages postés 1333 Date d'inscription lundi 22 septembre 2008 Statut Membre Dernière intervention 8 avril 2023 - 18 avril 2020 à 10:30
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
A voir également:

2 réponses

M-12 Messages postés 1333 Date d'inscription lundi 22 septembre 2008 Statut Membre Dernière intervention 8 avril 2023 299
18 avril 2020 à 09:07
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
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
M-12 Messages postés 1333 Date d'inscription lundi 22 septembre 2008 Statut Membre Dernière intervention 8 avril 2023 299 > Theyoshi
18 avril 2020 à 09:22
Re,
Sans voir ce qu'il y a dans le classeur ???
0
theyoshi Messages postés 10 Date d'inscription dimanche 19 juin 2005 Statut Membre Dernière intervention 18 avril 2020 > M-12 Messages postés 1333 Date d'inscription lundi 22 septembre 2008 Statut Membre Dernière intervention 8 avril 2023
18 avril 2020 à 09:37
Comment insérer un fichier dans ce forum ?
0
M-12 Messages postés 1333 Date d'inscription lundi 22 septembre 2008 Statut Membre Dernière intervention 8 avril 2023 299 > theyoshi Messages postés 10 Date d'inscription dimanche 19 juin 2005 Statut Membre Dernière intervention 18 avril 2020
18 avril 2020 à 09:39
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
theyoshi Messages postés 10 Date d'inscription dimanche 19 juin 2005 Statut Membre Dernière intervention 18 avril 2020 > M-12 Messages postés 1333 Date d'inscription lundi 22 septembre 2008 Statut Membre Dernière intervention 8 avril 2023
18 avril 2020 à 09:40
Merci, je ne connaissais pas ce principe.

Voici donc le lien : https://www.cjoint.com/c/JDshOtFILth
0
Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 1 775
18 avril 2020 à 09:12
Bonjour,

L'indentation du code permet d'éviter ce type d'erreur, voir :
https://silkyroad.developpez.com/VBA/DebuterMacros/#LV
0