Changer Nom de feuille dans toutes les lignes d'un code

Bonjour au forum,

J'ammène une question un peu Originale cette fois ci .

En fait j'éssai d'utiliser un de mes codes dans un autre classeur et pour l'adapter, il changer Feuil9 par feuil14. le problème c'est qu'il y'a plus de 500 lignes et ca sera fastudieux de faire le contrôle ligne par ligne

ma question est de savoir s'il y'aurait un moyen de faire une modification générale ? genre recherche et remplacer sur un code VBA.

Merci d'avance à vous,

Bonjour,

D'où l'intérêt d'utiliser une variable ou constante... Avec une constante, on n'a toujours qu'une modification à faire, en tête de procédure ou de module.

Ceci dit, tu peux facilement faire par une simple opération rechercher-remplacer (menu Edition > Rechercher).

Mais ce qui pose question c'est que tu sembles faire état d'une procédure de 500 lignes ! Ce qui paraît en principe excessif ! Il serait alors bon que tu soumettes ton code qui devrait pouvoir donner lieu à des simplifications notables.

Cordialement.

Merci MFERRAND pour la réponse,

je suis encore un débutant dans vba donc je suis vraiment préneur de nouvelle idées.

J'avais commencé à modifier le code manuellement je te l'envoi tel qu'il est actuellement.

Je sais ca va faire

Sub lissage()
On Error Resume Next
Dim sysdate As Date
'Sub Création_du_tableau_des_actions_du_mois()
sysdate = Format(DateSerial(Year(Date), Month(Date), Day(Date)), "dd/mm/yyyy")
sysdate4 = DateSerial(Year(Date), Month(Date) + 1, 0)
sysdate3 = DateSerial(Year(Date), Month(Date) + 2, 0)
sysdate2 = DateSerial(Year(Date), Month(Date) + 3, 0)
sysdate1 = DateSerial(Year(Date), Month(Date) + 4, 0)
sysdate0 = DateSerial(Year(Date), Month(Date) + 5, 0)
sysdate6 = DateSerial(Year(Date), Month(Date) + 6, 0)
sysdate7 = DateSerial(Year(Date), Month(Date) + 7, 0)
sysdate8 = DateSerial(Year(Date), Month(Date) + 8, 0)
sysdate9 = DateSerial(Year(Date), Month(Date) + 9, 0)
sysdate10 = DateSerial(Year(Date), Month(Date) + 10, 0)
sysdate11 = DateSerial(Year(Date), Month(Date) + 11, 0)
sysdate12 = DateSerial(Year(Date), Month(Date) + 12, 0)
n = Feuil14.Range("C" & Rows.Count).End(xlUp).Row
For m = 4 To n
a = 0
If Feuil14.Cells(m, 13).Interior.Color <> RGB(255, 0, 0) Or Feuil19.Cells(m, 13).Interior.Color <> RGB(255, 255, 0) Then
If Feuil14.Cells(m, 6) <= sysdate Then 'Actions en retard
If Feuil14.Cells(m, 8).Value = "AAE" Then 'AAE en retard
a = a + 1
o = Feuil3.Range("Z" & Rows.Count).End(xlUp).Row + 1
Feuil3.Cells(o, 24).Value = Feuil14.Cells(m, 1).Value
Feuil13.Cells(o, 25).Font.ColorIndex = Feuil14.Cells(m, 1).Font.ColorIndex
Feuil13.Cells(o, 1).Interior.Color = Feuil14.Cells(m, 1).Interior.Color
Feuil13.Cells(o, 2).Value = Feuil14.Cells(m, 2).Value
Feuil13.Cells(o, 2).Font.ColorIndex = Feuil14.Cells(m, 2).Font.ColorIndex
Feuil13.Cells(o, 2).Interior.Color = Feuil14.Cells(m, 2).Interior.Color
Feuil13.Cells(o, 3).Value = Feuil14.Cells(m, 3).Value
Feuil13.Cells(o, 3).Font.ColorIndex = Feuil14.Cells(m, 3).Font.ColorIndex
Feuil13.Cells(o, 3).Interior.Color = Feuil14.Cells(m, 3).Interior.Color
Feuil13.Cells(o, 3).Value = Feuil14.Cells(m, 4).Value
Feuil13.Cells(o, 4).Font.ColorIndex = Feuil14.Cells(m, 4).Font.ColorIndex
Feuil13.Cells(o, 4).Interior.Color = Feuil14.Cells(m, 4).Interior.Color
Feuil13.Cells(o, 5).Value = Feuil14.Cells(m, 5).Value
Feuil16.Cells(o, 5).Font.ColorIndex = Feuil9.Cells(m, 5).Font.ColorIndex
Feuil16.Cells(o, 5).Interior.Color = Feuil9.Cells(m, 5).Interior.Color
Feuil16.Cells(o, 6).Value = Feuil9.Cells(m, 6).Value
Feuil16.Cells(o, 6).Font.ColorIndex = Feuil9.Cells(m, 6).Font.ColorIndex
Feuil16.Cells(o, 6).Interior.Color = Feuil9.Cells(m, 6).Interior.Color
Feuil16.Cells(o, 7).Value = Feuil9.Cells(m, 7).Value
Feuil16.Cells(o, 7).Font.ColorIndex = Feuil9.Cells(m, 7).Font.ColorIndex
Feuil16.Cells(o, 7).Interior.Color = Feuil9.Cells(m, 7).Interior.Color
Feuil16.Cells(o, 8).Value = Feuil9.Cells(m, 8).Value
Feuil16.Cells(o, 8).Font.ColorIndex = Feuil9.Cells(m, 8).Font.ColorIndex
Feuil16.Cells(o, 8).Interior.Color = Feuil9.Cells(m, 8).Interior.Color
Feuil16.Cells(o, 9).Value = Feuil9.Cells(m, 9).Value
Feuil16.Cells(o, 9).Font.ColorIndex = Feuil9.Cells(m, 9).Font.ColorIndex
Feuil16.Cells(o, 9).Interior.Color = Feuil9.Cells(m, 9).Interior.Color
Feuil16.Cells(o, 10).Value = Feuil9.Cells(m, 10).Value
Feuil16.Cells(o, 10).Font.ColorIndex = Feuil9.Cells(m, 10).Font.ColorIndex
Feuil16.Cells(o, 10).Interior.Color = Feuil9.Cells(m, 10).Interior.Color
Feuil16.Cells(o, 11).Value = Feuil9.Cells(m, 11).Value
Feuil16.Cells(o, 11).Font.ColorIndex = Feuil9.Cells(m, 11).Font.ColorIndex
Feuil16.Cells(o, 11).Interior.Color = Feuil9.Cells(m, 11).Interior.Color
Feuil16.Cells(o, 12).Value = Feuil9.Cells(m, 12).Value
Feuil16.Cells(o, 12).Font.ColorIndex = Feuil9.Cells(m, 12).Font.ColorIndex
Feuil16.Cells(o, 12).Interior.Color = Feuil9.Cells(m, 12).Interior.Color
ElseIf sysdate6 < Feuil9.Cells(m, 6) And Feuil9.Cells(m, 6) <= sysdate7 Then 'Actions mois n+6
o = Feuil17.Range("C" & Rows.Count).End(xlUp).Row + 1
Feuil17.Cells(o, 1).Value = Feuil9.Cells(m, 1).Value
Feuil17.Cells(o, 1).Font.ColorIndex = Feuil9.Cells(m, 1).Font.ColorIndex
Feuil17.Cells(o, 1).Interior.Color = Feuil9.Cells(m, 1).Interior.Color
Feuil17.Cells(o, 2).Value = Feuil9.Cells(m, 2).Value
Feuil17.Cells(o, 2).Font.ColorIndex = Feuil9.Cells(m, 2).Font.ColorIndex
Feuil17.Cells(o, 2).Interior.Color = Feuil9.Cells(m, 2).Interior.Color
Feuil17.Cells(o, 3).Value = Feuil9.Cells(m, 3).Value
Feuil17.Cells(o, 3).Font.ColorIndex = Feuil9.Cells(m, 3).Font.ColorIndex
Feuil17.Cells(o, 3).Interior.Color = Feuil9.Cells(m, 3).Interior.Color
Feuil17.Cells(o, 4).Value = Feuil9.Cells(m, 4).Value
Feuil17.Cells(o, 4).Font.ColorIndex = Feuil9.Cells(m, 4).Font.ColorIndex
Feuil17.Cells(o, 4).Interior.Color = Feuil9.Cells(m, 4).Interior.Color
Feuil17.Cells(o, 5).Value = Feuil9.Cells(m, 5).Value
Feuil17.Cells(o, 5).Font.ColorIndex = Feuil9.Cells(m, 5).Font.ColorIndex
Feuil17.Cells(o, 5).Interior.Color = Feuil9.Cells(m, 5).Interior.Color
Feuil17.Cells(o, 6).Value = Feuil9.Cells(m, 6).Value
Feuil17.Cells(o, 6).Font.ColorIndex = Feuil9.Cells(m, 6).Font.ColorIndex
Feuil17.Cells(o, 6).Interior.Color = Feuil9.Cells(m, 6).Interior.Color
Feuil17.Cells(o, 7).Value = Feuil9.Cells(m, 7).Value
Feuil17.Cells(o, 7).Font.ColorIndex = Feuil9.Cells(m, 7).Font.ColorIndex
Feuil17.Cells(o, 7).Interior.Color = Feuil9.Cells(m, 7).Interior.Color
Feuil17.Cells(o, 8).Value = Feuil9.Cells(m, 8).Value
Feuil17.Cells(o, 8).Font.ColorIndex = Feuil9.Cells(m, 8).Font.ColorIndex
Feuil17.Cells(o, 8).Interior.Color = Feuil9.Cells(m, 8).Interior.Color
Feuil17.Cells(o, 9).Value = Feuil9.Cells(m, 9).Value
Feuil17.Cells(o, 9).Font.ColorIndex = Feuil9.Cells(m, 9).Font.ColorIndex
Feuil17.Cells(o, 9).Interior.Color = Feuil9.Cells(m, 9).Interior.Color
Feuil17.Cells(o, 10).Value = Feuil9.Cells(m, 10).Value
Feuil17.Cells(o, 10).Font.ColorIndex = Feuil9.Cells(m, 10).Font.ColorIndex
Feuil17.Cells(o, 10).Interior.Color = Feuil9.Cells(m, 10).Interior.Color
Feuil17.Cells(o, 11).Value = Feuil9.Cells(m, 11).Value
Feuil17.Cells(o, 11).Font.ColorIndex = Feuil9.Cells(m, 11).Font.ColorIndex
Feuil17.Cells(o, 11).Interior.Color = Feuil9.Cells(m, 11).Interior.Color
Feuil17.Cells(o, 12).Value = Feuil9.Cells(m, 12).Value
Feuil17.Cells(o, 12).Font.ColorIndex = Feuil9.Cells(m, 12).Font.ColorIndex
Feuil17.Cells(o, 12).Interior.Color = Feuil9.Cells(m, 12).Interior.Color
ElseIf sysdate7 < Feuil9.Cells(m, 6) And Feuil9.Cells(m, 6) <= sysdate8 Then 'Actions mois n+7
o = Feuil18.Range("C" & Rows.Count).End(xlUp).Row + 1
Feuil18.Cells(o, 1).Value = Feuil9.Cells(m, 1).Value
Feuil18.Cells(o, 1).Font.ColorIndex = Feuil9.Cells(m, 1).Font.ColorIndex
Feuil18.Cells(o, 1).Interior.Color = Feuil9.Cells(m, 1).Interior.Color
Feuil18.Cells(o, 2).Value = Feuil9.Cells(m, 2).Value
Feuil18.Cells(o, 2).Font.ColorIndex = Feuil9.Cells(m, 2).Font.ColorIndex
Feuil18.Cells(o, 2).Interior.Color = Feuil9.Cells(m, 2).Interior.Color
Feuil18.Cells(o, 3).Value = Feuil9.Cells(m, 3).Value
Feuil18.Cells(o, 3).Font.ColorIndex = Feuil9.Cells(m, 3).Font.ColorIndex
Feuil18.Cells(o, 3).Interior.Color = Feuil9.Cells(m, 3).Interior.Color
Feuil18.Cells(o, 4).Value = Feuil9.Cells(m, 4).Value
Feuil18.Cells(o, 4).Font.ColorIndex = Feuil9.Cells(m, 4).Font.ColorIndex
Feuil18.Cells(o, 4).Interior.Color = Feuil9.Cells(m, 4).Interior.Color
Feuil18.Cells(o, 5).Value = Feuil9.Cells(m, 5).Value
Feuil18.Cells(o, 5).Font.ColorIndex = Feuil9.Cells(m, 5).Font.ColorIndex
Feuil18.Cells(o, 5).Interior.Color = Feuil9.Cells(m, 5).Interior.Color
Feuil18.Cells(o, 6).Value = Feuil9.Cells(m, 6).Value
Feuil18.Cells(o, 6).Font.ColorIndex = Feuil9.Cells(m, 6).Font.ColorIndex
Feuil18.Cells(o, 6).Interior.Color = Feuil9.Cells(m, 6).Interior.Color
Feuil18.Cells(o, 7).Value = Feuil9.Cells(m, 7).Value
Feuil18.Cells(o, 7).Font.ColorIndex = Feuil9.Cells(m, 7).Font.ColorIndex
Feuil18.Cells(o, 7).Interior.Color = Feuil9.Cells(m, 7).Interior.Color
Feuil18.Cells(o, 8).Value = Feuil9.Cells(m, 8).Value
Feuil18.Cells(o, 8).Font.ColorIndex = Feuil9.Cells(m, 8).Font.ColorIndex
Feuil18.Cells(o, 8).Interior.Color = Feuil9.Cells(m, 8).Interior.Color
Feuil18.Cells(o, 9).Value = Feuil9.Cells(m, 9).Value
Feuil18.Cells(o, 9).Font.ColorIndex = Feuil9.Cells(m, 9).Font.ColorIndex
Feuil18.Cells(o, 9).Interior.Color = Feuil9.Cells(m, 9).Interior.Color
Feuil18.Cells(o, 10).Value = Feuil9.Cells(m, 10).Value
Feuil18.Cells(o, 10).Font.ColorIndex = Feuil9.Cells(m, 10).Font.ColorIndex
Feuil18.Cells(o, 10).Interior.Color = Feuil9.Cells(m, 10).Interior.Color
Feuil18.Cells(o, 11).Value = Feuil9.Cells(m, 11).Value
Feuil18.Cells(o, 11).Font.ColorIndex = Feuil9.Cells(m, 11).Font.ColorIndex
Feuil18.Cells(o, 11).Interior.Color = Feuil9.Cells(m, 11).Interior.Color
Feuil18.Cells(o, 12).Value = Feuil9.Cells(m, 12).Value
Feuil18.Cells(o, 12).Font.ColorIndex = Feuil9.Cells(m, 12).Font.ColorIndex
Feuil18.Cells(o, 12).Interior.Color = Feuil9.Cells(m, 12).Interior.Color
ElseIf sysdate8 < Feuil9.Cells(m, 6) And Feuil9.Cells(m, 6) <= sysdate9 Then 'Actions mois n+8
o = Feuil19.Range("C" & Rows.Count).End(xlUp).Row + 1
Feuil19.Cells(o, 1).Value = Feuil9.Cells(m, 1).Value
Feuil19.Cells(o, 1).Font.ColorIndex = Feuil9.Cells(m, 1).Font.ColorIndex
Feuil19.Cells(o, 1).Interior.Color = Feuil9.Cells(m, 1).Interior.Color
Feuil19.Cells(o, 2).Value = Feuil9.Cells(m, 2).Value
Feuil19.Cells(o, 2).Font.ColorIndex = Feuil9.Cells(m, 2).Font.ColorIndex
Feuil19.Cells(o, 2).Interior.Color = Feuil9.Cells(m, 2).Interior.Color
Feuil19.Cells(o, 3).Value = Feuil9.Cells(m, 3).Value
Feuil19.Cells(o, 3).Font.ColorIndex = Feuil9.Cells(m, 3).Font.ColorIndex
Feuil19.Cells(o, 3).Interior.Color = Feuil9.Cells(m, 3).Interior.Color
Feuil19.Cells(o, 4).Value = Feuil9.Cells(m, 4).Value
Feuil19.Cells(o, 4).Font.ColorIndex = Feuil9.Cells(m, 4).Font.ColorIndex
Feuil19.Cells(o, 4).Interior.Color = Feuil9.Cells(m, 4).Interior.Color
Feuil19.Cells(o, 5).Value = Feuil9.Cells(m, 5).Value
Feuil19.Cells(o, 5).Font.ColorIndex = Feuil9.Cells(m, 5).Font.ColorIndex
Feuil19.Cells(o, 5).Interior.Color = Feuil9.Cells(m, 5).Interior.Color
Feuil19.Cells(o, 6).Value = Feuil9.Cells(m, 6).Value
Feuil19.Cells(o, 6).Font.ColorIndex = Feuil9.Cells(m, 6).Font.ColorIndex
Feuil19.Cells(o, 6).Interior.Color = Feuil9.Cells(m, 6).Interior.Color
Feuil19.Cells(o, 7).Value = Feuil9.Cells(m, 7).Value
Feuil19.Cells(o, 7).Font.ColorIndex = Feuil9.Cells(m, 7).Font.ColorIndex
Feuil19.Cells(o, 7).Interior.Color = Feuil9.Cells(m, 7).Interior.Color
Feuil19.Cells(o, 8).Value = Feuil9.Cells(m, 8).Value
Feuil19.Cells(o, 8).Font.ColorIndex = Feuil9.Cells(m, 8).Font.ColorIndex
Feuil19.Cells(o, 8).Interior.Color = Feuil9.Cells(m, 8).Interior.Color
Feuil19.Cells(o, 9).Value = Feuil9.Cells(m, 9).Value
Feuil19.Cells(o, 9).Font.ColorIndex = Feuil9.Cells(m, 9).Font.ColorIndex
Feuil19.Cells(o, 9).Interior.Color = Feuil9.Cells(m, 9).Interior.Color
Feuil19.Cells(o, 10).Value = Feuil9.Cells(m, 10).Value
Feuil19.Cells(o, 10).Font.ColorIndex = Feuil9.Cells(m, 10).Font.ColorIndex
Feuil19.Cells(o, 10).Interior.Color = Feuil9.Cells(m, 10).Interior.Color
Feuil19.Cells(o, 11).Value = Feuil9.Cells(m, 11).Value
Feuil19.Cells(o, 11).Font.ColorIndex = Feuil9.Cells(m, 11).Font.ColorIndex
Feuil19.Cells(o, 11).Interior.Color = Feuil9.Cells(m, 11).Interior.Color
Feuil19.Cells(o, 12).Value = Feuil9.Cells(m, 12).Value
Feuil19.Cells(o, 12).Font.ColorIndex = Feuil9.Cells(m, 12).Font.ColorIndex
Feuil19.Cells(o, 12).Interior.Color = Feuil9.Cells(m, 12).Interior.Color
ElseIf sysdate9 < Feuil9.Cells(m, 6) And Feuil9.Cells(m, 6) <= sysdate10 Then 'Actions mois n+9
o = Feuil20.Range("C" & Rows.Count).End(xlUp).Row + 1
Feuil20.Cells(o, 1).Value = Feuil9.Cells(m, 1).Value
Feuil20.Cells(o, 1).Font.ColorIndex = Feuil9.Cells(m, 1).Font.ColorIndex
Feuil20.Cells(o, 1).Interior.Color = Feuil9.Cells(m, 1).Interior.Color
Feuil20.Cells(o, 2).Value = Feuil9.Cells(m, 2).Value
Feuil20.Cells(o, 2).Font.ColorIndex = Feuil9.Cells(m, 2).Font.ColorIndex
Feuil20.Cells(o, 2).Interior.Color = Feuil9.Cells(m, 2).Interior.Color
Feuil20.Cells(o, 3).Value = Feuil9.Cells(m, 3).Value
Feuil20.Cells(o, 3).Font.ColorIndex = Feuil9.Cells(m, 3).Font.ColorIndex
Feuil20.Cells(o, 3).Interior.Color = Feuil9.Cells(m, 3).Interior.Color
Feuil20.Cells(o, 4).Value = Feuil9.Cells(m, 4).Value
Feuil20.Cells(o, 4).Font.ColorIndex = Feuil9.Cells(m, 4).Font.ColorIndex
Feuil20.Cells(o, 4).Interior.Color = Feuil9.Cells(m, 4).Interior.Color
Feuil20.Cells(o, 5).Value = Feuil9.Cells(m, 5).Value
Feuil20.Cells(o, 5).Font.ColorIndex = Feuil9.Cells(m, 5).Font.ColorIndex
Feuil20.Cells(o, 5).Interior.Color = Feuil9.Cells(m, 5).Interior.Color
Feuil20.Cells(o, 6).Value = Feuil9.Cells(m, 6).Value
Feuil20.Cells(o, 6).Font.ColorIndex = Feuil9.Cells(m, 6).Font.ColorIndex
Feuil20.Cells(o, 6).Interior.Color = Feuil9.Cells(m, 6).Interior.Color
Feuil20.Cells(o, 7).Value = Feuil9.Cells(m, 7).Value
Feuil20.Cells(o, 7).Font.ColorIndex = Feuil9.Cells(m, 7).Font.ColorIndex
Feuil20.Cells(o, 7).Interior.Color = Feuil9.Cells(m, 7).Interior.Color
Feuil20.Cells(o, 8).Value = Feuil9.Cells(m, 8).Value
Feuil20.Cells(o, 8).Font.ColorIndex = Feuil9.Cells(m, 8).Font.ColorIndex
Feuil20.Cells(o, 8).Interior.Color = Feuil9.Cells(m, 8).Interior.Color
Feuil20.Cells(o, 9).Value = Feuil9.Cells(m, 9).Value
Feuil20.Cells(o, 9).Font.ColorIndex = Feuil9.Cells(m, 9).Font.ColorIndex
Feuil20.Cells(o, 9).Interior.Color = Feuil9.Cells(m, 9).Interior.Color
Feuil20.Cells(o, 10).Value = Feuil9.Cells(m, 10).Value
Feuil20.Cells(o, 10).Font.ColorIndex = Feuil9.Cells(m, 10).Font.ColorIndex
Feuil20.Cells(o, 10).Interior.Color = Feuil9.Cells(m, 10).Interior.Color
Feuil20.Cells(o, 11).Value = Feuil9.Cells(m, 11).Value
Feuil20.Cells(o, 11).Font.ColorIndex = Feuil9.Cells(m, 11).Font.ColorIndex
Feuil20.Cells(o, 11).Interior.Color = Feuil9.Cells(m, 11).Interior.Color
Feuil20.Cells(o, 12).Value = Feuil9.Cells(m, 12).Value
Feuil20.Cells(o, 12).Font.ColorIndex = Feuil9.Cells(m, 12).Font.ColorIndex
Feuil20.Cells(o, 12).Interior.Color = Feuil9.Cells(m, 12).Interior.Color
ElseIf sysdate10 < Feuil9.Cells(m, 6) And Feuil9.Cells(m, 6) <= sysdate11 Then 'Actions mois n+10
o = Feuil21.Range("C" & Rows.Count).End(xlUp).Row + 1
Feuil21.Cells(o, 1).Value = Feuil9.Cells(m, 1).Value
Feuil21.Cells(o, 1).Font.ColorIndex = Feuil9.Cells(m, 1).Font.ColorIndex
Feuil21.Cells(o, 1).Interior.Color = Feuil9.Cells(m, 1).Interior.Color
Feuil21.Cells(o, 2).Value = Feuil9.Cells(m, 2).Value
Feuil21.Cells(o, 2).Font.ColorIndex = Feuil9.Cells(m, 2).Font.ColorIndex
Feuil21.Cells(o, 2).Interior.Color = Feuil9.Cells(m, 2).Interior.Color
Feuil21.Cells(o, 3).Value = Feuil9.Cells(m, 3).Value
Feuil21.Cells(o, 3).Font.ColorIndex = Feuil9.Cells(m, 3).Font.ColorIndex
Feuil21.Cells(o, 3).Interior.Color = Feuil9.Cells(m, 3).Interior.Color
Feuil21.Cells(o, 4).Value = Feuil9.Cells(m, 4).Value
Feuil21.Cells(o, 4).Font.ColorIndex = Feuil9.Cells(m, 4).Font.ColorIndex
Feuil21.Cells(o, 4).Interior.Color = Feuil9.Cells(m, 4).Interior.Color
Feuil21.Cells(o, 5).Value = Feuil9.Cells(m, 5).Value
Feuil21.Cells(o, 5).Font.ColorIndex = Feuil9.Cells(m, 5).Font.ColorIndex
Feuil21.Cells(o, 5).Interior.Color = Feuil9.Cells(m, 5).Interior.Color
Feuil21.Cells(o, 6).Value = Feuil9.Cells(m, 6).Value
Feuil21.Cells(o, 6).Font.ColorIndex = Feuil9.Cells(m, 6).Font.ColorIndex
Feuil21.Cells(o, 6).Interior.Color = Feuil9.Cells(m, 6).Interior.Color
Feuil21.Cells(o, 7).Value = Feuil9.Cells(m, 7).Value
Feuil21.Cells(o, 7).Font.ColorIndex = Feuil9.Cells(m, 7).Font.ColorIndex
Feuil21.Cells(o, 7).Interior.Color = Feuil9.Cells(m, 7).Interior.Color
Feuil21.Cells(o, 8).Value = Feuil9.Cells(m, 8).Value
Feuil21.Cells(o, 8).Font.ColorIndex = Feuil9.Cells(m, 8).Font.ColorIndex
Feuil21.Cells(o, 8).Interior.Color = Feuil9.Cells(m, 8).Interior.Color
Feuil21.Cells(o, 9).Value = Feuil9.Cells(m, 9).Value
Feuil21.Cells(o, 9).Font.ColorIndex = Feuil9.Cells(m, 9).Font.ColorIndex
Feuil21.Cells(o, 9).Interior.Color = Feuil9.Cells(m, 9).Interior.Color
Feuil21.Cells(o, 10).Value = Feuil9.Cells(m, 10).Value
Feuil21.Cells(o, 10).Font.ColorIndex = Feuil9.Cells(m, 10).Font.ColorIndex
Feuil21.Cells(o, 10).Interior.Color = Feuil9.Cells(m, 10).Interior.Color
Feuil21.Cells(o, 11).Value = Feuil9.Cells(m, 11).Value
Feuil21.Cells(o, 11).Font.ColorIndex = Feuil9.Cells(m, 11).Font.ColorIndex
Feuil21.Cells(o, 11).Interior.Color = Feuil9.Cells(m, 11).Interior.Color
Feuil21.Cells(o, 12).Value = Feuil9.Cells(m, 12).Value
Feuil21.Cells(o, 12).Font.ColorIndex = Feuil9.Cells(m, 12).Font.ColorIndex
Feuil21.Cells(o, 12).Interior.Color = Feuil9.Cells(m, 12).Interior.Color
ElseIf sysdate11 < Feuil9.Cells(m, 6) And Feuil9.Cells(m, 6) <= sysdate12 Then 'Actions mois n+11
o = Feuil22.Range("C" & Rows.Count).End(xlUp).Row + 1
Feuil22.Cells(o, 1).Value = Feuil9.Cells(m, 1).Value
Feuil22.Cells(o, 1).Font.ColorIndex = Feuil9.Cells(m, 1).Font.ColorIndex
Feuil22.Cells(o, 1).Interior.Color = Feuil9.Cells(m, 1).Interior.Color
Feuil22.Cells(o, 2).Value = Feuil9.Cells(m, 2).Value
Feuil22.Cells(o, 2).Font.ColorIndex = Feuil9.Cells(m, 2).Font.ColorIndex
Feuil22.Cells(o, 2).Interior.Color = Feuil9.Cells(m, 2).Interior.Color
Feuil22.Cells(o, 3).Value = Feuil9.Cells(m, 3).Value
Feuil22.Cells(o, 3).Font.ColorIndex = Feuil9.Cells(m, 3).Font.ColorIndex
Feuil22.Cells(o, 3).Interior.Color = Feuil9.Cells(m, 3).Interior.Color
Feuil22.Cells(o, 4).Value = Feuil9.Cells(m, 4).Value
Feuil22.Cells(o, 4).Font.ColorIndex = Feuil9.Cells(m, 4).Font.ColorIndex
Feuil22.Cells(o, 4).Interior.Color = Feuil9.Cells(m, 4).Interior.Color
Feuil22.Cells(o, 5).Value = Feuil9.Cells(m, 5).Value
Feuil22.Cells(o, 5).Font.ColorIndex = Feuil9.Cells(m, 5).Font.ColorIndex
Feuil22.Cells(o, 5).Interior.Color = Feuil9.Cells(m, 5).Interior.Color
Feuil22.Cells(o, 6).Value = Feuil9.Cells(m, 6).Value
Feuil22.Cells(o, 6).Font.ColorIndex = Feuil9.Cells(m, 6).Font.ColorIndex
Feuil22.Cells(o, 6).Interior.Color = Feuil9.Cells(m, 6).Interior.Color
Feuil22.Cells(o, 7).Value = Feuil9.Cells(m, 7).Value
Feuil22.Cells(o, 7).Font.ColorIndex = Feuil9.Cells(m, 7).Font.ColorIndex
Feuil22.Cells(o, 7).Interior.Color = Feuil9.Cells(m, 7).Interior.Color
Feuil22.Cells(o, 8).Value = Feuil9.Cells(m, 8).Value
Feuil22.Cells(o, 8).Font.ColorIndex = Feuil9.Cells(m, 8).Font.ColorIndex
Feuil22.Cells(o, 8).Interior.Color = Feuil9.Cells(m, 8).Interior.Color
Feuil22.Cells(o, 9).Value = Feuil9.Cells(m, 9).Value
Feuil22.Cells(o, 9).Font.ColorIndex = Feuil9.Cells(m, 9).Font.ColorIndex
Feuil22.Cells(o, 9).Interior.Color = Feuil9.Cells(m, 9).Interior.Color
Feuil22.Cells(o, 10).Value = Feuil9.Cells(m, 10).Value
Feuil22.Cells(o, 10).Font.ColorIndex = Feuil9.Cells(m, 10).Font.ColorIndex
Feuil22.Cells(o, 10).Interior.Color = Feuil9.Cells(m, 10).Interior.Color
Feuil22.Cells(o, 11).Value = Feuil9.Cells(m, 11).Value
Feuil22.Cells(o, 11).Font.ColorIndex = Feuil9.Cells(m, 11).Font.ColorIndex
Feuil22.Cells(o, 11).Interior.Color = Feuil9.Cells(m, 11).Interior.Color
Feuil22.Cells(o, 12).Value = Feuil9.Cells(m, 12).Value
Feuil22.Cells(o, 12).Font.ColorIndex = Feuil9.Cells(m, 12).Font.ColorIndex
Feuil22.Cells(o, 12).Interior.Color = Feuil9.Cells(m, 12).Interior.Color
End If
End If
Next
'mise en forme des tableau
o = Feuil16.Range("C" & Rows.Count).End(xlUp).Row
Feuil16.Range("A2:L" & o).Borders.Weight = 2
For i = 2 To o
If Feuil16.Cells(i, 2).Interior.Color = RGB(250, 150, 50) Then
Feuil16.Cells(i, 13).Value = 1
End If
Next
o = Feuil17.Range("C" & Rows.Count).End(xlUp).Row
Feuil17.Range("A2:L" & o).Borders.Weight = 2
For j = 2 To o
If Feuil17.Cells(j, 2).Interior.Color = RGB(250, 150, 50) Then
Feuil17.Cells(j, 13).Value = 1
End If
Next
o = Feuil18.Range("C" & Rows.Count).End(xlUp).Row
Feuil18.Range("A2:L" & o).Borders.Weight = 2
For k = 2 To o
If Feuil18.Cells(k, 2).Interior.Color = RGB(250, 150, 50) Then
Feuil18.Cells(k, 13).Value = 1
End If
Next
o = Feuil19.Range("C" & Rows.Count).End(xlUp).Row
Feuil19.Range("A2:L" & o).Borders.Weight = 2
For l = 2 To o
If Feuil19.Cells(l, 2).Interior.Color = RGB(250, 150, 50) Then
Feuil19.Cells(l, 13).Value = 1
End If
Next
o = Feuil20.Range("C" & Rows.Count).End(xlUp).Row
Feuil20.Range("A2:L" & o).Borders.Weight = 2
For m = 2 To o
If Feuil20.Cells(m, 2).Interior.Color = RGB(250, 150, 50) Then
Feuil20.Cells(m, 13).Value = 1
End If
Next
o = Feuil21.Range("C" & Rows.Count).End(xlUp).Row
Feuil21.Range("A2:L" & o).Borders.Weight = 2
For n = 2 To o
If Feuil21.Cells(n, 2).Interior.Color = RGB(250, 150, 50) Then
Feuil21.Cells(n, 13).Value = 1
End If
Next
o = Feuil22.Range("C" & Rows.Count).End(xlUp).Row
Feuil22.Range("A2:L" & o).Borders.Weight = 2
For p = 2 To o
If Feuil22.Cells(p, 2).Interior.Color = RGB(250, 150, 50) Then
Feuil22.Cells(p, 13).Value = 1
End If
Next
'nombre d'actions mois n+5
n = Feuil16.Range("C" & Rows.Count).End(xlUp).Row
p = Application.WorksheetFunction.CountIfs(Feuil16.Range("B2:B" & n), "AC", Feuil16.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil16.Range("B2:B" & n), "AC")
Feuil1.Range("G134").Value = p
Feuil1.Range("H134").Value = o - p
p = Application.WorksheetFunction.CountIfs(Feuil16.Range("B2:B" & n), "SDA", Feuil16.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil16.Range("B2:B" & n), "SDA")
Feuil1.Range("G135").Value = p
'nombre d'actions mois n+6
n = Feuil17.Range("C" & Rows.Count).End(xlUp).Row
p = Application.WorksheetFunction.CountIfs(Feuil17.Range("B2:B" & n), "AC", Feuil17.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil17.Range("B2:B" & n), "AC")
Feuil1.Range("G137").Value = p
Feuil1.Range("H137").Value = o - p
p = Application.WorksheetFunction.CountIfs(Feuil17.Range("B2:B" & n), "SDA", Feuil17.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil17.Range("B2:B" & n), "SDA")
Feuil1.Range("G138").Value = p
'nombre d'actions mois n+7
n = Feuil18.Range("C" & Rows.Count).End(xlUp).Row
p = Application.WorksheetFunction.CountIfs(Feuil18.Range("B2:B" & n), "AC", Feuil18.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil18.Range("B2:B" & n), "AC")
Feuil1.Range("G140").Value = p
Feuil1.Range("H140").Value = o - p
p = Application.WorksheetFunction.CountIfs(Feuil18.Range("B2:B" & n), "SDA", Feuil18.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil18.Range("B2:B" & n), "SDA")
Feuil1.Range("G141").Value = p
'nombre d'actions mois n+8
n = Feuil19.Range("C" & Rows.Count).End(xlUp).Row
p = Application.WorksheetFunction.CountIfs(Feuil19.Range("B2:B" & n), "AC", Feuil19.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil19.Range("B2:B" & n), "AC")
Feuil1.Range("G143").Value = p
Feuil1.Range("H143").Value = o - p
p = Application.WorksheetFunction.CountIfs(Feuil19.Range("B2:B" & n), "SDA", Feuil19.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil19.Range("B2:B" & n), "SDA")
Feuil1.Range("G144").Value = p
'nombre d'actions mois n+9
n = Feuil20.Range("C" & Rows.Count).End(xlUp).Row
p = Application.WorksheetFunction.CountIfs(Feuil20.Range("B2:B" & n), "AC", Feuil20.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil20.Range("B2:B" & n), "AC")
Feuil1.Range("G146").Value = p
Feuil1.Range("H146").Value = o - p
p = Application.WorksheetFunction.CountIfs(Feuil20.Range("B2:B" & n), "SDA", Feuil20.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil20.Range("B2:B" & n), "SDA")
Feuil1.Range("G147").Value = p
'nombre d'actions mois n+10
n = Feuil21.Range("C" & Rows.Count).End(xlUp).Row
p = Application.WorksheetFunction.CountIfs(Feuil21.Range("B2:B" & n), "AC", Feuil21.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil21.Range("B2:B" & n), "AC")
Feuil1.Range("G149").Value = p
Feuil1.Range("H149").Value = o - p
p = Application.WorksheetFunction.CountIfs(Feuil21.Range("B2:B" & n), "SDA", Feuil21.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil21.Range("B2:B" & n), "SDA")
Feuil1.Range("G150").Value = p
'nombre d'actions mois n+11
n = Feuil22.Range("C" & Rows.Count).End(xlUp).Row
p = Application.WorksheetFunction.CountIfs(Feuil22.Range("B2:B" & n), "AC", Feuil22.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil22.Range("B2:B" & n), "AC")
Feuil1.Range("G152").Value = p
Feuil1.Range("H152").Value = o - p
p = Application.WorksheetFunction.CountIfs(Feuil22.Range("B2:B" & n), "SDA", Feuil22.Range("M2:M" & n), "1")
o = Application.WorksheetFunction.CountIf(Feuil22.Range("B2:B" & n), "SDA")
Feuil1.Range("G153").Value = p
'remplissage des mois considérés
a = Month(sysdate6)
Feuil1.Range("E134").Value = a
a = Month(sysdate7)
Feuil1.Range("E137").Value = a
a = Month(sysdate8)
Feuil1.Range("E140").Value = a
a = Month(sysdate9)
Feuil1.Range("E143").Value = a
a = Month(sysdate10)
Feuil1.Range("E146").Value = a
a = Month(sysdate11)
Feuil1.Range("E149").Value = a
a = Month(sysdate12)
Feuil1.Range("E152").Value = a
For i = 134 To 152
If Feuil1.Range("E" & i).Value = 1 Then
Feuil1.Range("E" & i).Value = "Janvier"
ElseIf Feuil1.Range("E" & i).Value = 2 Then
Feuil1.Range("E" & i).Value = "Février"
ElseIf Feuil1.Range("E" & i).Value = 3 Then
Feuil1.Range("E" & i).Value = "Mars"
ElseIf Feuil1.Range("E" & i).Value = 4 Then
Feuil1.Range("E" & i).Value = "Avril"
ElseIf Feuil1.Range("E" & i).Value = 5 Then
Feuil1.Range("E" & i).Value = "Mai"
ElseIf Feuil1.Range("E" & i).Value = 6 Then
Feuil1.Range("E" & i).Value = "Juin"
ElseIf Feuil1.Range("E" & i).Value = 7 Then
Feuil1.Range("E" & i).Value = "Juillet"
ElseIf Feuil1.Range("E" & i).Value = 8 Then
Feuil1.Range("E" & i).Value = "Août"
ElseIf Feuil1.Range("E" & i).Value = 9 Then
Feuil1.Range("E" & i).Value = "Septembre"
ElseIf Feuil1.Range("E" & i).Value = 10 Then
Feuil1.Range("E" & i).Value = "Octobre"
ElseIf Feuil1.Range("E" & i).Value = 11 Then
Feuil1.Range("E" & i).Value = "Novembre"
ElseIf Feuil1.Range("E" & i).Value = 12 Then
Feuil1.Range("E" & i).Value = "Décembre"
End If
Next
End Sub

Sauf erreur car : code non indenté, variables non déclarées, des flottements dans les noms de feuille, un End If manquant...

une première réduction purement formelle (car on doit pouvoir faire mieux en repensant le programme à la source...

Sub lissage()
    Dim sysdate(12) As Date, i%, n%, m%, o%, p%, a%, Feuil As Worksheet
    'Sub Création_du_tableau_des_actions_du_mois()
    For i = 1 To 5
        sysdate(5 - i) = DateSerial(Year(Date), Month(Date) + i, 0)
    Next i
    For i = 6 To 12
        sysdate(i) = DateSerial(Year(Date), Month(Date) + i, 0)
    Next i
    n = Feuil14.Range("C" & Rows.Count).End(xlUp).Row
    For m = 4 To n
        If Feuil14.Cells(m, 13).Interior.Color <> vbRed Or Feuil19.Cells(m, 13).Interior.Color _
         <> vbYellow Then
            If Feuil14.Cells(m, 6) <= Date Then 'Actions en retard
                If Feuil14.Cells(m, 8).Value = "AAE" Then 'AAE en retard
                    o = Feuil3.Range("Z" & Rows.Count).End(xlUp).Row + 1
                    Feuil13.Cells(o, 24) = Feuil14.Cells(m, 1) 'Feuil3?
                    Feuil13.Cells(o, 25).Font.Color = Feuil14.Cells(m, 1).Font.Color
                    Feuil13.Cells(o, 1).Interior.Color = Feuil14.Cells(m, 1).Interior.Color
                    For i = 2 To 4
                        Feuil13.Cells(o, i) = Feuil14.Cells(m, i)
                        Feuil13.Cells(o, i).Font.Color = Feuil14.Cells(m, i).Font.Color
                        Feuil13.Cells(o, i).Interior.Color = Feuil14.Cells(m, i).Interior.Color
                    Next i
                    For i = 5 To 12
                        Feuil16.Cells(o, i) = Feuil14.Cells(m, i)
                        Feuil16.Cells(o, i).Font.Color = Feuil14.Cells(m, i).Font.Color
                        Feuil16.Cells(o, i).Interior.Color = Feuil14.Cells(m, i).Interior.Color
                    Next i
                End If
            Else
                If Feuil14.Cells(m, 6) > sysdate(6) And Feuil14.Cells(m, 6) <= sysdate(7) Then
                    Set Feuil = Feuil17
                ElseIf Feuil14.Cells(m, 6) > sysdate(7) And Feuil14.Cells(m, 6) <= sysdate(8) Then
                    Set Feuil = Feuil18
                ElseIf Feuil14.Cells(m, 6) > sysdate(8) And Feuil14.Cells(m, 6) <= sysdate(9) Then
                    Set Feuil = Feuil19
                ElseIf Feuil14.Cells(m, 6) > sysdate(9) And Feuil14.Cells(m, 6) <= sysdate(10) Then
                    Set Feuil = Feuil20
                ElseIf Feuil14.Cells(m, 6) > sysdate(10) And Feuil14.Cells(m, 6) <= sysdate(11) Then
                    Set Feuil = Feuil21
                ElseIf Feuil14.Cells(m, 6) > sysdate(11) And Feuil14.Cells(m, 6) <= sysdate(12) Then
                    Set Feuil = Feuil22
                End If
                If Not Feuil Is Nothing Then
                    o = Feuil.Range("C" & Rows.Count).End(xlUp).Row + 1
                    For i = 1 To 12
                        Feuil.Cells(o, i) = Feuil14.Cells(m, i)
                        Feuil.Cells(o, i).Font.Color = Feuil14.Cells(m, i).Font.Color
                        Feuil.Cells(o, i).Interior.Color = Feuil14.Cells(m, i).Interior.Color
                    Next i
                End If
            End If
        End If
    Next m
    'mise en forme des tableau, nombre d'actions mois, remplissage des mois
    Set Feuil = Nothing
    For Each Feuil In Worksheets
        m = Val(Replace(Feuil.CodeName, "Feuil", ""))
        If m >= 16 And m <= 22 Then
            n = Feuil.Range("C" & Rows.Count).End(xlUp).Row
            Feuil.Range("A2:L" & n).Borders.Weight = xlThin
            For i = 2 To n
                If Feuil.Cells(i, 2).Interior.Color = RGB(250, 150, 50) Then Feuil.Cells(i, 13) = 1
            Next i
            o = WorksheetFunction.CountIf(Feuil.Range("B2:B" & n), "AC")
            p = WorksheetFunction.CountIfs(Feuil.Range("B2:B" & n), "AC", Feuil.Range("M2:M" & n), "1")
            Feuil1.Cells(m * 3 + 86, 7) = p
            Feuil1.Cells(m * 3 + 86, 8) = o - p
            p = WorksheetFunction.CountIfs(Feuil.Range("B2:B" & n), "SDA", Feuil.Range("M2:M" & n), "1")
            Feuil1.Cells(m * 3 + 87, 7) = p
            a = Month(sysdate(m - 10))
            Feuil1.Cells(m * 3 + 86, 5) = StrConv(MonthName(a), vbProperCase)
        End If
    Next Feuil
End Sub

73 lignes de code, déclarations comprises.

Cordialement.

Nickel !

C'est fou comme l'utilisation des boucles peuvent faire les choses.

En plus ça marche super bien.

Merci MFerrand et merci le Forrum,

Tant mieux donc ! Bonne continuation.

Merci MFERRAND,

Je reviens vers toi avec un autre code suis entrain d'éssayer, c'est toujours dans l'optique de raccourcir mes lignes de code.

Il sagit d'une boucle avec renvoie vers une ligne par goto mais le problème est qu'après la fin de l'exécution du goto, le programme s'arrête sans revenir à la boucle. je ne sais pas comment mettre une instruction à la fin du goto pour revenir à la boucle.

goto est-elle la fonction appropriée? ou faut-il le faire avec une autre fonction.

ci-dessous le code, en te remerciant d'avane

Sub exemple()
For m = 4 To n
If Feuil14.Cells(m, 8).Value = "AAE" Then 'AAE en retard
a = a + 1
nomFeuille = Feuil1
GoTo Line1
If Feuil14.Cells(m, 1).Value = "Equipe A" Then 'AAE en retard EQA
b = b + 1
nomFeuille = Feuil
GoTo Line1
ElseIf Feuil14.Cells(m, 1).Value = "Equipe B" Then 'AAE en retard EQB
c = c + 1
nomFeuille = Feuil3
GoTo Line1

Line1:
o = ThisWorkbook.Worksheets(nomFeuille).Range("Z" & Rows.Count).End(xlUp).Row + 1
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 24).Value = Feuil14.Cells(m, 1).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 24).Font.ColorIndex = Feuil14.Cells(m, 1).Font.ColorIndex
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 24).Interior.Color = Feuil14.Cells(m, 1).Interior.Color
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 25).Value = Feuil14.Cells(m, 2).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 25).Font.ColorIndex = Feuil14.Cells(m, 2).Font.ColorIndex
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 25).Interior.Color = Feuil14.Cells(m, 2).Interior.Color
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 26).Value = Feuil14.Cells(m, 3).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 26).Font.ColorIndex = Feuil14.Cells(m, 3).Font.ColorIndex
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 26).Interior.Color = Feuil14.Cells(m, 3).Interior.Color
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 27).Value = Feuil14.Cells(m, 4).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 27).Font.ColorIndex = Feuil14.Cells(m, 4).Font.ColorIndex
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 27).Interior.Color = Feuil14.Cells(m, 4).Interior.Color
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 28).Value = Feuil14.Cells(m, 5).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 28).Font.ColorIndex = Feuil14.Cells(m, 5).Font.ColorIndex
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 28).Interior.Color = Feuil14.Cells(m, 5).Interior.Color
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 29).Value = Feuil14.Cells(m, 6).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 29).Font.ColorIndex = Feuil14.Cells(m, 6).Font.ColorIndex
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 29).Interior.Color = Feuil14.Cells(m, 6).Interior.Color
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 30).Value = Feuil14.Cells(m, 7).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 31).Value = Feuil14.Cells(m, 8).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 32).Value = Feuil14.Cells(m, 9).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 33).Value = Feuil14.Cells(m, 10).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 34).Value = Feuil14.Cells(m, 11).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 35).Value = Feuil14.Cells(m, 12).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 36).Value = Feuil14.Cells(m, 13).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 37).Value = Feuil14.Cells(m, 14).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 38).Value = Feuil14.Cells(m, 15).Value
ThisWorkbook.Worksheets(nomFeuille).Cells(o, 42).Value = Feuil14.Cells(m, 19).Value
'Là je veux revenir à la ligne du goto pour continuer la boucle
'goto if ?
End If
End If
Next
End Sub

Bonjour,

D'abord, si tu indentes ton code tu en verras beaucoup mieux la structure...

Il est vrai que GoTo peut rendre quelques services lorsqu'on n'a pas d'autre moyen de s'extraire d'un déroulement procédural. A titre d'exemple je l'ai utilisé récemment pour sortir d'une double boucle lorsqu'une condition était vérifiée, un Exit For ne me faisait sortir que de la boucle interne... Mais il faut veiller à ce que le déroulement logique se poursuive à partir du branchement...

Dans ton cas, tu boucles sur les lignes d'une feuille, à chaque ligne tu testes des conditions qui te permettent de définir la variable nomFeuille avec laquelle tu vas travailler... Il te faut boucler complètement l'instruction conditionnelle dans cette phase, en prévoyant le cas où nomFeuille ne sera pas définie : dans ce cas, tu peux utiliser GoTo pour shunter les instructions de travail sur nomFeuille et passer à la ligne suivante ! (mais à la place, tu pouvais simplement définir nomFeuille = "" et mettre sous condition que nomFeuille <>"" la suite de ta procédure...)

Il y avait aussi d'autres éléments à rectifier, l'utilisation du CodeName peut présenter quelques avantages mais présente des particularités d'utilisation dont il faut tenir compte.

Sub exemple()
    Dim nomFeuille$, m%, n%
    n = Feuil14.Range("A" & Rows.Count).End(xlUp).Row
    For m = 4 To n
        With Feuil14
            If .Cells(m, 8) = "AAE" Then
                nomFeuille = Feuil1.Name
            ElseIf .Cells(m, 1) = "Equipe A" Then
                nomFeuille = Feuil2.Name
            ElseIf .Cells(m, 1) = "Equipe B" Then
                nomFeuille = Feuil3.Name
            Else
                GoTo LSuiv
            End If
        End With
        'Instructions utilisant nomFeuille
LSuiv:
    Next m
End Sub

Cordialement.

Bonjour à tous,

une façon de se passer du Goto :

Sub exemple()
    Dim nomFeuille$, m%, n%, ok As Boolean
    n = Feuil14.Range("A" & Rows.Count).End(xlUp).Row
    For m = 4 To n
        With Feuil14
            If .Cells(m, 8) = "AAE" Then
                nomFeuille = Feuil1.Name: ok = True
            ElseIf .Cells(m, 1) = "Equipe A" Then
                nomFeuille = Feuil2.Name: ok = True
            ElseIf .Cells(m, 1) = "Equipe B" Then
                nomFeuille = Feuil3.Name: ok = True
            End If
        End With
        If ok Then
            'Instructions utilisant nomFeuille
        End If
    Next m
End Sub

eric

Rechercher des sujets similaires à "changer nom feuille toutes lignes code"