Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

XL 2013 repeter une action plusieurs fois

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 !

cabaniais

XLDnaute Nouveau
bonjour
je voudrais qu'a l'ouverture de mon dossier cette action se repete 3 fois .
j'ai reussi a le faire en copiant 3 fois la meme macro.
ce que je voudrais c'est faire une boucle pour que ce soit plus simple.
voici ma macro
merci d'avance
Private Sub Workbook_Open()

Range("j2").Select
If Selection <= Date Then
Range("j2;p2").Select
Selection.Copy
Range("A15:G15").Select
Selection.Insert Shift:=xlDown
Range("j2").Select
Application.CutCopyMode = False
Range("m2").Select
If ActiveCell = "eurofil" Then
Range("j2") = DateAdd("m", 3, Range("j2"))
Application.CutCopyMode = False
Else: Range("j2") = DateAdd("m", 1, Range("j2"))
End If
End If

Range("J2;13").Select
ActiveWorkbook.Worksheets("ccp").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ccp").Sort.SortFields.Add Key:=Range("J2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("ccp").Sort
.SetRange Range("J2;13")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Range("j2").Select
If Selection <= Date Then
Range("j2;p2").Select
Selection.Copy
Range("A15:G15").Select
Selection.Insert Shift:=xlDown
Range("j2").Select
Application.CutCopyMode = False
Range("m2").Select
If ActiveCell = "eurofil" Then
Range("j2") = DateAdd("m", 3, Range("j2"))
Application.CutCopyMode = False
Else: Range("j2") = DateAdd("m", 1, Range("j2"))
End If
End If

Range("J2;13").Select
ActiveWorkbook.Worksheets("ccp").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ccp").Sort.SortFields.Add Key:=Range("J2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("ccp").Sort
.SetRange Range("J2;13")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("j2").Select
If Selection <= Date Then
Range("j2;p2").Select
Selection.Copy
Range("A15:G15").Select
Selection.Insert Shift:=xlDown
Range("j2").Select
Application.CutCopyMode = False
Range("m2").Select
If ActiveCell = "eurofil" Then
Range("j2") = DateAdd("m", 3, Range("j2"))
Application.CutCopyMode = False
Else: Range("j2") = DateAdd("m", 1, Range("j2"))
End If
End If

Range("J2;13").Select
ActiveWorkbook.Worksheets("ccp").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ccp").Sort.SortFields.Add Key:=Range("J2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("ccp").Sort
.SetRange Range("J2;13")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

End Sub
 
Dernière édition:
sinon, ton code allégé, et corrigé donnerait ceci
VB:
For i = 1 To 3
    If Range("j2") <= Date Then
        Range("j2:p2").Copy
        Range("A15:G15").Insert Shift:=xlDown
        Application.CutCopyMode = False
        If Range("m2") = "eurofil" Then
            Range("j2") = DateAdd("m", 3, Range("j2"))
        Else: Range("j2") = DateAdd("m", 1, Range("j2"))
        End If
    End If
   
    ActiveWorkbook.Worksheets("ccp").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("ccp").Sort.SortFields.Add Key:=Range("J2"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("ccp").Sort
        .SetRange Range("J2:13")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
Next i
 
 
ok merci beaucoup c'est exactement ce que je voulais faire. et en plus c'est beaucoup plus simple.
c'est ma 1er "creation" en macro et j'avais reussi a faire quelque chose mais en compliquant la macro.
merci encore
 
- 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

  • Question Question
XL 2021 listbox
Réponses
18
Affichages
296
Réponses
17
Affichages
1 K
Réponses
4
Affichages
206
Réponses
11
Affichages
785
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…