Simplification avec Boucle??

  • Initiateur de la discussion Initiateur de la discussion Gexk5
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Gexk5

XLDnaute Occasionnel
Bonsoir le forum,
Je vous propose une macro, est il possible de simplifier en faisant une boucle???

Sub Verif()
'Mise à jour de la base de donnée
LigneNom = xindex + 5 'Ligne du Nom
If Cells(LigneNom, 9) = "" And Cells(LigneNom, 12) > "0" And Cells(LigneNom, 12) > (Cells(LigneNom, 10) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else

End If
End If
If Cells(LigneNom, 14) = "" And Cells(LigneNom, 17) > "0" And Cells(LigneNom, 17) > (Cells(LigneNom, 15) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else

End If
End If
If Cells(LigneNom, 19) = "" And Cells(LigneNom, 22) > "0" And Cells(LigneNom, 22) > (Cells(LigneNom, 20) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else

End If
End If
If Cells(LigneNom, 24) = "" And Cells(LigneNom, 27) > "0" And Cells(LigneNom, 27) > (Cells(LigneNom, 25) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else

End If
End If
If Cells(LigneNom, 29) = "" And Cells(LigneNom, 32) > "0" And Cells(LigneNom, 32) > (Cells(LigneNom, 30) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else

End If
End If
If Cells(LigneNom, 34) = "" And Cells(LigneNom, 37) > "0" And Cells(LigneNom, 37) > (Cells(LigneNom, 35) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else

End If
End If
If Cells(LigneNom, 39) = "" And Cells(LigneNom, 42) > "0" And Cells(LigneNom, 42) > (Cells(LigneNom, 40) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else

End If
End If
If Cells(LigneNom, 44) = "" And Cells(LigneNom, 47) > "0" And Cells(LigneNom, 47) > (Cells(LigneNom, 45) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else

End If
End If
If Cells(LigneNom, 49) = "" And Cells(LigneNom, 52) > "0" And Cells(LigneNom, 52) > (Cells(LigneNom, 50) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else

End If
End If
If Cells(LigneNom, 54) = "" And Cells(LigneNom, 57) > "0" And Cells(LigneNom, 57) > (Cells(LigneNom, 55) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else
End If
End If
End Sub


Merci de vos reponses
 
Re : Simplification avec Boucle??

Et pour ca , c'est possible???

Sub AbsencePresence()
' les absencs fonction de présence à 1/3
Dim Absence, Presence As Integer

Absence = Absence1.Value
Presence = Presence1.Value
If Absence * 3 < Presence Then Absence1.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui1 = True Then Absence1.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui1 = False Then Absence1.BackColor = &HFF&

Absence = Absence2.Value
Presence = Presence2.Value
If Absence * 3 < Presence Then Absence2.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui2 = True Then Absence2.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui2 = False Then Absence2.BackColor = &HFF&

Absence = Absence3.Value
Presence = Presence3.Value
If Absence * 3 < Presence Then Absence3.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui3 = True Then Absence3.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui3 = False Then Absence3.BackColor = &HFF&

Absence = Absence4.Value
Presence = Presence4.Value
If Absence * 3 < Presence Then Absence4.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui4 = True Then Absence4.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui4 = False Then Absence4.BackColor = &HFF&

Absence = Absence5.Value
Presence = Presence5.Value
If Absence * 3 < Presence Then Absence5.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui5 = True Then Absence5.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui5 = False Then Absence5.BackColor = &HFF&

Absence = Absence6.Value
Presence = Presence6.Value
If Absence * 3 < Presence Then Absence6.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui6 = True Then Absence6.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui6 = False Then Absence6.BackColor = &HFF&

Absence = Absence7.Value
Presence = Presence7.Value
If Absence * 3 < Presence Then Absence7.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui7 = True Then Absence7.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui7 = False Then Absence7.BackColor = &HFF&

Absence = Absence8.Value
Presence = Presence8.Value
If Absence * 3 < Presence Then Absence8.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui8 = True Then Absence8.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui8 = False Then Absence8.BackColor = &HFF&

Absence = Absence9.Value
Presence = Presence9.Value
If Absence * 3 < Presence Then Absence9.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui9 = True Then Absence9.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui9 = False Then Absence9.BackColor = &HFF&

Absence = Absence10.Value
Presence = Presence10.Value
If Absence * 3 < Presence Then Absence10.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui10 = True Then Absence10.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui10 = False Then Absence10.BackColor = &HFF&
End Sub


Merci d'avance
 
Re : Simplification avec Boucle??

Bonsoir,

Alors pour la première, sans fichier c'est difficile de démêler sans se tromper.

Pour la première essaies un truc comme ceci:

Dim i as integer

For i=1 to 10

Absence =Me.controls("Absence" & i).Value
Presence = Me.controls("Presence" & i).Value
If Absence * 3 < Presence Then Absence10.BackColor = &HFF00& ' &H80FF80
If Absence * 3 >= Presence And CongeOui10 = True Then Absence10.BackColor = &H80C0FF
If Absence * 3 >= Presence And CongeOui10 = False Then Absence10.BackColor = &HFF&
Next

A bientôt
 
Re : Simplification avec Boucle??

Bonsoir,

Sub Verif()
'Mise à jour de la base de donnée
LigneNom = xindex + 5 'Ligne du Nom
If Cells(LigneNom, 9) = "" And Cells(LigneNom, 12) > "0" And Cells(LigneNom, 12) > _ (Cells(LigneNom, 10) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else....
.....
If Cells(LigneNom, 54) = "" And Cells(LigneNom, 57) > "0" And Cells(LigneNom, 57) > (Cells(LigneNom, 55) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show
Else
End If
End If
End Sub
A priori et sans garantie puisque pas de fichier...
Sub Verif()
'Mise à jour de la base de donnée
LigneNom = xindex + 5 'Ligne du Nom
For i = 9 to 54 step 5
If Cells(LigneNom, i) = "" And Cells(LigneNom, i + 3) > "0" And Cells(LigneNom, i + 3) > _ (Cells(LigneNom, i + 1) / 3) Then
Msg = "Voulez vous éffacer l'historique pour cette personne?" ' Définit le message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Définit les boutons.
Title = "TIER TEMPS DEPASSE !!!!!!! " ' Définit le titre.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' L'utilisateur a choisi Oui.
RAZInterimaire.Show 'que ce passe t-il ici
Else....'et là
End if
End if
Next i
End sub

A+
kjin
 
Dernière édition:
Re : Simplification avec Boucle??

bonsoir à tous

s'il s'agit bien de controles:

Code:
Sub AbsencePresence()
' les absencs fonction de présence à 1/3
Dim Absence, Presence As Integer
Dim CtrlAbsence As Control, CtrlCongeOui As Control, CtrlPresence As Control

Set CtrlAbsence = Absence1: Set CtrlCongeOui = CongeOui1: Set CtrlPresence = Presence1: GoSub Traitement
Set CtrlAbsence = Absence2: Set CtrlCongeOui = CongeOui2: Set CtrlPresence = Presence2: GoSub Traitement
Set CtrlAbsence = Absence3: Set CtrlCongeOui = CongeOui3: Set CtrlPresence = Presence3: GoSub Traitement
Set CtrlAbsence = Absence4: Set CtrlCongeOui = CongeOui4: Set CtrlPresence = Presence4: GoSub Traitement
Set CtrlAbsence = Absence5: Set CtrlCongeOui = CongeOui5: Set CtrlPresence = Presence5: GoSub Traitement
Set CtrlAbsence = Absence6: Set CtrlCongeOui = CongeOui6: Set CtrlPresence = Presence6: GoSub Traitement
Set CtrlAbsence = Absence7: Set CtrlCongeOui = CongeOui7: Set CtrlPresence = Presence7: GoSub Traitement
Set CtrlAbsence = Absence8: Set CtrlCongeOui = CongeOui8: Set CtrlPresence = Presence8: GoSub Traitement
Set CtrlAbsence = Absence9: Set CtrlCongeOui = CongeOui9: Set CtrlPresence = Presence9: GoSub Traitement
Set CtrlAbsence = Absence10: Set CtrlCongeOui = CongeOui10: Set CtrlPresence = Presence10: GoSub Traitement
Exit Sub
Traitement:
Absence = CtrlAbsence.Value * 3
Presence = CtrlPresence.Value
If Absence < Presence Then CtrlAbsence.BackColor = &HFF00&  ' &H80FF80
If Absence >= Presence And CtrlCongeOui = True Then CtrlAbsence.BackColor = &H80C0FF
If Absence >= Presence And CtrlCongeOui = False Then CtrlAbsence.BackColor = &HFF&
Return
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Retour