A voir également:
- Macro Excel 2007
- Telecharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Liste déroulante excel - Guide
- Save as pdf office 2007 - Télécharger - Bureautique
- Word et excel gratuit - Guide
- Si et excel - Guide
9 réponses
Patrice33740
Messages postés
8561
Date d'inscription
dimanche 13 juin 2010
Statut
Membre
Dernière intervention
15 mars 2025
1 779
7 nov. 2011 à 21:37
7 nov. 2011 à 21:37
Mais quelle est donc cette mystérieuse macro ?
Euh, il n'y a rien de mystérieux là-dedans, c'est moi qui a créé ma propre macro. Et c'en est une toute simple.
T'as jamais créé de macro ?
T'as jamais créé de macro ?
pijaku
Messages postés
12263
Date d'inscription
jeudi 15 mai 2008
Statut
Modérateur
Dernière intervention
4 janvier 2024
2 757
8 nov. 2011 à 14:23
8 nov. 2011 à 14:23
Salut El-sol.
Salut Patrice,
à el sol : Ca c'est de la bonne réponse!!!
Je traduis donc les propos de Patrice :
Pourrais tu compléter ta demande en venant coller ici le code complet de ta macro, indispensable pour pouvoir t'apporter une réponse cohérente.
Salut Patrice,
à el sol : Ca c'est de la bonne réponse!!!
Je traduis donc les propos de Patrice :
Pourrais tu compléter ta demande en venant coller ici le code complet de ta macro, indispensable pour pouvoir t'apporter une réponse cohérente.
salut pijaku,
"ça, c'est de la bonne question" :)
voici ma macro et que je ne réussis même plus à exécuter sans bug:
Sub TRIER()
'
' TRIER Macro
' tri
'
' Touche de raccourci du clavier: Ctrl+i
'
Columns("A:C").Select
Range("C1").Activate
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("D:F").Select
Selection.Style = "Comma"
Columns("B:C").Select
Selection.ColumnWidth = 26.71
Columns("G:H").Select
Selection.ClearContents
Range("A3").Select
ActiveWindow.LargeScroll Down:=1
Range("A28").Select
ActiveWindow.LargeScroll Down:=1
Range("A53").Select
ActiveWindow.LargeScroll Down:=1
Range("A78").Select
ActiveWindow.LargeScroll Down:=1
Range("A103").Select
ActiveWindow.LargeScroll Down:=1
Range("A128").Select
ActiveWindow.LargeScroll Down:=1
Range("A153").Select
ActiveWindow.LargeScroll Down:=1
Range("A178").Select
ActiveWindow.LargeScroll Down:=1
Range("A203").Select
ActiveWindow.LargeScroll Down:=1
Range("A228").Select
ActiveWindow.LargeScroll Down:=1
Range("A253").Select
ActiveWindow.LargeScroll Down:=1
Range("A278").Select
ActiveWindow.LargeScroll Down:=1
Range("A303").Select
ActiveWindow.LargeScroll Down:=1
Range("A328").Select
ActiveWindow.LargeScroll Down:=1
Range("A353").Select
ActiveWindow.LargeScroll Down:=1
Range("A378").Select
ActiveWindow.LargeScroll Down:=1
Range("A403").Select
ActiveWindow.LargeScroll Down:=1
Range("A428").Select
ActiveWindow.LargeScroll Down:=1
Range("A453").Select
ActiveWindow.LargeScroll Down:=1
Range("A478").Select
ActiveWindow.LargeScroll Down:=1
Range("A503").Select
ActiveWindow.LargeScroll Down:=1
Range("A528").Select
ActiveWindow.LargeScroll Down:=1
Range("A553").Select
ActiveWindow.LargeScroll Down:=1
Range("A578").Select
ActiveWindow.LargeScroll Down:=1
Range("A603").Select
ActiveWindow.LargeScroll Down:=1
Range("A628").Select
ActiveWindow.LargeScroll Down:=1
Range("A653").Select
ActiveWindow.LargeScroll Down:=1
Range("A678").Select
ActiveWindow.LargeScroll Down:=1
Range("A703").Select
ActiveWindow.LargeScroll Down:=1
Range("A728").Select
ActiveWindow.LargeScroll Down:=1
Range("A753").Select
ActiveWindow.LargeScroll Down:=1
Range("A778").Select
ActiveWindow.LargeScroll Down:=1
Range("A803").Select
ActiveWindow.LargeScroll Down:=1
Range("A828").Select
ActiveWindow.LargeScroll Down:=1
Range("A853").Select
ActiveWindow.LargeScroll Down:=1
Range("A878").Select
ActiveWindow.LargeScroll Down:=1
Range("A903").Select
ActiveWindow.LargeScroll Down:=1
Range("A928").Select
ActiveWindow.LargeScroll Down:=1
Range("A953").Select
ActiveWindow.LargeScroll Down:=1
Range("A978").Select
ActiveWindow.LargeScroll Down:=1
Rows("1001:1001").Select
ActiveWindow.ScrollRow = 999
ActiveWindow.ScrollRow = 997
ActiveWindow.ScrollRow = 990
ActiveWindow.ScrollRow = 978
ActiveWindow.ScrollRow = 930
ActiveWindow.ScrollRow = 902
ActiveWindow.ScrollRow = 869
ActiveWindow.ScrollRow = 831
ActiveWindow.ScrollRow = 787
ActiveWindow.ScrollRow = 745
ActiveWindow.ScrollRow = 701
ActiveWindow.ScrollRow = 654
ActiveWindow.ScrollRow = 619
ActiveWindow.ScrollRow = 572
ActiveWindow.ScrollRow = 539
ActiveWindow.ScrollRow = 493
ActiveWindow.ScrollRow = 444
ActiveWindow.ScrollRow = 404
ActiveWindow.ScrollRow = 354
ActiveWindow.ScrollRow = 312
ActiveWindow.ScrollRow = 272
ActiveWindow.ScrollRow = 243
ActiveWindow.ScrollRow = 186
ActiveWindow.ScrollRow = 123
ActiveWindow.ScrollRow = 87
ActiveWindow.ScrollRow = 58
ActiveWindow.ScrollRow = 22
ActiveWindow.ScrollRow = 14
ActiveWindow.ScrollRow = 1
Rows("3:1001").Select
Range("A1001").Activate
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Add Key:=Range _
("E3:E282"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Add Key:=Range _
("D3:D282"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("20111108083259(1)").Sort
.SetRange Range("A3:H282")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A3").Select
End Sub
"ça, c'est de la bonne question" :)
voici ma macro et que je ne réussis même plus à exécuter sans bug:
Sub TRIER()
'
' TRIER Macro
' tri
'
' Touche de raccourci du clavier: Ctrl+i
'
Columns("A:C").Select
Range("C1").Activate
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("D:F").Select
Selection.Style = "Comma"
Columns("B:C").Select
Selection.ColumnWidth = 26.71
Columns("G:H").Select
Selection.ClearContents
Range("A3").Select
ActiveWindow.LargeScroll Down:=1
Range("A28").Select
ActiveWindow.LargeScroll Down:=1
Range("A53").Select
ActiveWindow.LargeScroll Down:=1
Range("A78").Select
ActiveWindow.LargeScroll Down:=1
Range("A103").Select
ActiveWindow.LargeScroll Down:=1
Range("A128").Select
ActiveWindow.LargeScroll Down:=1
Range("A153").Select
ActiveWindow.LargeScroll Down:=1
Range("A178").Select
ActiveWindow.LargeScroll Down:=1
Range("A203").Select
ActiveWindow.LargeScroll Down:=1
Range("A228").Select
ActiveWindow.LargeScroll Down:=1
Range("A253").Select
ActiveWindow.LargeScroll Down:=1
Range("A278").Select
ActiveWindow.LargeScroll Down:=1
Range("A303").Select
ActiveWindow.LargeScroll Down:=1
Range("A328").Select
ActiveWindow.LargeScroll Down:=1
Range("A353").Select
ActiveWindow.LargeScroll Down:=1
Range("A378").Select
ActiveWindow.LargeScroll Down:=1
Range("A403").Select
ActiveWindow.LargeScroll Down:=1
Range("A428").Select
ActiveWindow.LargeScroll Down:=1
Range("A453").Select
ActiveWindow.LargeScroll Down:=1
Range("A478").Select
ActiveWindow.LargeScroll Down:=1
Range("A503").Select
ActiveWindow.LargeScroll Down:=1
Range("A528").Select
ActiveWindow.LargeScroll Down:=1
Range("A553").Select
ActiveWindow.LargeScroll Down:=1
Range("A578").Select
ActiveWindow.LargeScroll Down:=1
Range("A603").Select
ActiveWindow.LargeScroll Down:=1
Range("A628").Select
ActiveWindow.LargeScroll Down:=1
Range("A653").Select
ActiveWindow.LargeScroll Down:=1
Range("A678").Select
ActiveWindow.LargeScroll Down:=1
Range("A703").Select
ActiveWindow.LargeScroll Down:=1
Range("A728").Select
ActiveWindow.LargeScroll Down:=1
Range("A753").Select
ActiveWindow.LargeScroll Down:=1
Range("A778").Select
ActiveWindow.LargeScroll Down:=1
Range("A803").Select
ActiveWindow.LargeScroll Down:=1
Range("A828").Select
ActiveWindow.LargeScroll Down:=1
Range("A853").Select
ActiveWindow.LargeScroll Down:=1
Range("A878").Select
ActiveWindow.LargeScroll Down:=1
Range("A903").Select
ActiveWindow.LargeScroll Down:=1
Range("A928").Select
ActiveWindow.LargeScroll Down:=1
Range("A953").Select
ActiveWindow.LargeScroll Down:=1
Range("A978").Select
ActiveWindow.LargeScroll Down:=1
Rows("1001:1001").Select
ActiveWindow.ScrollRow = 999
ActiveWindow.ScrollRow = 997
ActiveWindow.ScrollRow = 990
ActiveWindow.ScrollRow = 978
ActiveWindow.ScrollRow = 930
ActiveWindow.ScrollRow = 902
ActiveWindow.ScrollRow = 869
ActiveWindow.ScrollRow = 831
ActiveWindow.ScrollRow = 787
ActiveWindow.ScrollRow = 745
ActiveWindow.ScrollRow = 701
ActiveWindow.ScrollRow = 654
ActiveWindow.ScrollRow = 619
ActiveWindow.ScrollRow = 572
ActiveWindow.ScrollRow = 539
ActiveWindow.ScrollRow = 493
ActiveWindow.ScrollRow = 444
ActiveWindow.ScrollRow = 404
ActiveWindow.ScrollRow = 354
ActiveWindow.ScrollRow = 312
ActiveWindow.ScrollRow = 272
ActiveWindow.ScrollRow = 243
ActiveWindow.ScrollRow = 186
ActiveWindow.ScrollRow = 123
ActiveWindow.ScrollRow = 87
ActiveWindow.ScrollRow = 58
ActiveWindow.ScrollRow = 22
ActiveWindow.ScrollRow = 14
ActiveWindow.ScrollRow = 1
Rows("3:1001").Select
Range("A1001").Activate
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Add Key:=Range _
("E3:E282"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Add Key:=Range _
("D3:D282"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("20111108083259(1)").Sort
.SetRange Range("A3:H282")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A3").Select
End Sub
pijaku
Messages postés
12263
Date d'inscription
jeudi 15 mai 2008
Statut
Modérateur
Dernière intervention
4 janvier 2024
2 757
8 nov. 2011 à 14:47
8 nov. 2011 à 14:47
Premier travail à faire : supprimer toutes les lignes inutiles :
ActiveWindow.ScrollRow
ActiveWindow.LargeScroll Down:=1
...
ActiveWindow.ScrollRow
ActiveWindow.LargeScroll Down:=1
...
est-ce que c'est mieux comme ça ?
Sub tries()
'
' tries Macro
' tri
'
' Touche de raccourci du clavier: Ctrl+o
'
Columns("A:C").Select
Range("C1").Activate
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("D:F").Select
Selection.Style = "Comma"
Columns("B:C").Select
Selection.ColumnWidth = 26
Columns("G:H").Select
Selection.ClearContents
Range("A4").Select
ActiveWindow.LargeScroll Down:=1
Range("A1154").Select
ActiveWindow.LargeScroll Down:=1
Rows("1179:1179").Select
ActiveWindow.ScrollRow = 1000
ActiveWindow.ScrollRow = 1
Rows("3:1000").Select
Range("A1000").Activate
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Add Key:=Range _
("E3:E282"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Add Key:=Range _
("D3:D282"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("20111108083259(1)").Sort
.SetRange Range("A3:H282")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A3").Select
End Sub
Sub tries()
'
' tries Macro
' tri
'
' Touche de raccourci du clavier: Ctrl+o
'
Columns("A:C").Select
Range("C1").Activate
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("D:F").Select
Selection.Style = "Comma"
Columns("B:C").Select
Selection.ColumnWidth = 26
Columns("G:H").Select
Selection.ClearContents
Range("A4").Select
ActiveWindow.LargeScroll Down:=1
Range("A1154").Select
ActiveWindow.LargeScroll Down:=1
Rows("1179:1179").Select
ActiveWindow.ScrollRow = 1000
ActiveWindow.ScrollRow = 1
Rows("3:1000").Select
Range("A1000").Activate
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Add Key:=Range _
("E3:E282"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("20111108083259(1)").Sort.SortFields.Add Key:=Range _
("D3:D282"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("20111108083259(1)").Sort
.SetRange Range("A3:H282")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A3").Select
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Patrice33740
Messages postés
8561
Date d'inscription
dimanche 13 juin 2010
Statut
Membre
Dernière intervention
15 mars 2025
1 779
8 nov. 2011 à 15:34
8 nov. 2011 à 15:34
Essaie de remplacer ton code par celui-ci qui s'applique à la feuille active :
Sous réserve que les colonnes à trier soient les mêmes.
Sub TRIER() ActiveSheet.Columns("A:C").HorizontalAlignment = xlLeft ActiveSheet.Columns("D:F").Style = "Comma" ActiveSheet.Columns("B:C").ColumnWidth = 26.71 ActiveSheet.Columns("G:H").ClearContents With ActiveSheet.Sort .SortFields.Clear .SortFields.Add Key:=Range("E3:E1000"), SortOn:=xlSortOnValues, _ Order:=xlAscending, DataOption:=xlSortNormal .SortFields.Add Key:=Range("D3:D1000"), SortOn:=xlSortOnValues, _ Order:=xlAscending, DataOption:=xlSortNormal .SetRange Range("A3:H1000") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With ActiveSheet.Range("A3").Select End Sub
Sous réserve que les colonnes à trier soient les mêmes.
les colonnes seront toujours les mêmes. C'est le nombre de rangées qui peut varier. C'est pour ça que j'y vais jusqu'à 1000 pour me donner une très grande marge de manoeuvre.
Pour le moment, la macro fonctionne mais juste dans l'onglet où la macro a été créée.
Ce qui n'est pas bon car à chaque mois, j'aurai à downloader des états de compte bancaire de plusieurs compagnies. Donc, dans des fichiers différents et dans des onglets différents. Je n'ai pas envie de créer une macro à chaque fois. Il faut qu'elle soit accessible à chaque fois que j'en ai envie.
Présentement, si j'essaie la macro dans un 2e onglet, ça me dit que la macro est désactivée.
Pour le moment, la macro fonctionne mais juste dans l'onglet où la macro a été créée.
Ce qui n'est pas bon car à chaque mois, j'aurai à downloader des états de compte bancaire de plusieurs compagnies. Donc, dans des fichiers différents et dans des onglets différents. Je n'ai pas envie de créer une macro à chaque fois. Il faut qu'elle soit accessible à chaque fois que j'en ai envie.
Présentement, si j'essaie la macro dans un 2e onglet, ça me dit que la macro est désactivée.
Patrice33740
Messages postés
8561
Date d'inscription
dimanche 13 juin 2010
Statut
Membre
Dernière intervention
15 mars 2025
1 779
8 nov. 2011 à 16:21
8 nov. 2011 à 16:21
Pour que la macro fonctionne sur n'importe quelle feuille du classeur, au lieu de la mettre dans une feuille, il faut la mettre dans un module standard.
Mais attention car ta macro ne dispose d'aucune sécurité pour contrôler si elle s'exécute dans une feuille adéquate
Mais attention car ta macro ne dispose d'aucune sécurité pour contrôler si elle s'exécute dans une feuille adéquate
J'ai pas besoin de sécurité, c'est juste moi qui l'utilise sur mon ordi.
comment je fais pour la mettre dans un module standard ?
les options qui sont là, lorsque je veux créer une macro, sont:
enregistrer la macro dans:
ce classeur
nouveau classeur
classeur de macros personnelles
J'ai essayé la dernière option et je n'ai aucune espèce d'idée où est rendue ma macro. Où est rendu ce fichier ?
comment je fais pour la mettre dans un module standard ?
les options qui sont là, lorsque je veux créer une macro, sont:
enregistrer la macro dans:
ce classeur
nouveau classeur
classeur de macros personnelles
J'ai essayé la dernière option et je n'ai aucune espèce d'idée où est rendue ma macro. Où est rendu ce fichier ?
pijaku
Messages postés
12263
Date d'inscription
jeudi 15 mai 2008
Statut
Modérateur
Dernière intervention
4 janvier 2024
2 757
8 nov. 2011 à 16:49
8 nov. 2011 à 16:49
comment je fais pour la mettre dans un module standard ?
- tu ouvres ton classeur,
- Tapes ALT+F11
- Insertion/Module
- copie/colle le code
- ferme la fenêtre Visual Basic Editor
Pour lancer la macro ALT+F8 depuis n'importe qu'elle feuille, sélectionnes TRIER et clic sur exécuter... Ou affectes là à un bouton...
- tu ouvres ton classeur,
- Tapes ALT+F11
- Insertion/Module
- copie/colle le code
Sub TRIER() ActiveSheet.Columns("A:C").HorizontalAlignment = xlLeft ActiveSheet.Columns("D:F").Style = "Comma" ActiveSheet.Columns("B:C").ColumnWidth = 26.71 ActiveSheet.Columns("G:H").ClearContents With ActiveSheet.Sort .SortFields.Clear .SortFields.Add Key:=Range("E3:E1000"), SortOn:=xlSortOnValues, _ Order:=xlAscending, DataOption:=xlSortNormal .SortFields.Add Key:=Range("D3:D1000"), SortOn:=xlSortOnValues, _ Order:=xlAscending, DataOption:=xlSortNormal .SetRange Range("A3:H1000") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With ActiveSheet.Range("A3").Select End Sub
- ferme la fenêtre Visual Basic Editor
Pour lancer la macro ALT+F8 depuis n'importe qu'elle feuille, sélectionnes TRIER et clic sur exécuter... Ou affectes là à un bouton...
8 nov. 2011 à 14:23
Je n'y connais pas grand chose mais comme tu dis que ta macro ne fonctionne qu'avec cette feuille peut être est-elle attachée à cette feuille pour le voir tu click sur l'onglet de la feuille voir code.