Problème macro boucle avec range...
jufabref
Messages postés
2
Statut
Membre
-
jufabref Messages postés 2 Statut Membre -
jufabref Messages postés 2 Statut Membre -
Bonjour à tous,
J'ai un petit problème avec une macro, je n'arrive pas à faire de boucle avec la fonction Range.
J'ai la macro suivante (ci-dessous) qui s'applique aux colonnes A et B (je l'ai enregistrée sous Excel). J'aimerais l'automatisée pour quelle me fasse la même chose sur les colonnes de A à AZ... Il faut donc sans doute une boucle for avec une variable..(je ne suis pas arrivé à la faire fonctionnée...)
Sub Tri()
'
' Tri Macro
'
' Touche de raccourci du clavier: Ctrl+i
'
Columns("A:A").Select
ActiveWorkbook.Worksheets("Scheduling").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Scheduling").Sort.SortFields.Add Key:=Range("A1") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Scheduling").Sort
.SetRange Range("A2:A996")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("B:B").Select
ActiveWorkbook.Worksheets("Scheduling").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Scheduling").Sort.SortFields.Add Key:=Range("B1") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Scheduling").Sort
.SetRange Range("B2:B996")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Je vous remercie d'avance.
Ju
J'ai un petit problème avec une macro, je n'arrive pas à faire de boucle avec la fonction Range.
J'ai la macro suivante (ci-dessous) qui s'applique aux colonnes A et B (je l'ai enregistrée sous Excel). J'aimerais l'automatisée pour quelle me fasse la même chose sur les colonnes de A à AZ... Il faut donc sans doute une boucle for avec une variable..(je ne suis pas arrivé à la faire fonctionnée...)
Sub Tri()
'
' Tri Macro
'
' Touche de raccourci du clavier: Ctrl+i
'
Columns("A:A").Select
ActiveWorkbook.Worksheets("Scheduling").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Scheduling").Sort.SortFields.Add Key:=Range("A1") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Scheduling").Sort
.SetRange Range("A2:A996")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("B:B").Select
ActiveWorkbook.Worksheets("Scheduling").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Scheduling").Sort.SortFields.Add Key:=Range("B1") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Scheduling").Sort
.SetRange Range("B2:B996")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Je vous remercie d'avance.
Ju
A voir également:
- Problème macro boucle avec range...
- Telecharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Télécharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Jitbit macro recorder - Télécharger - Confidentialité
- Out of range - Forum Windows
- D'sub out of range - Forum Ecran
2 réponses
Bonjour,
'Column("A:A") correspond a Column(1), B=2 ........
'Range("A1") correspond Cells(1,1) , B1---> Cells(1,2)
Sub Tri()
'
' Tri Macro
'
' Touche de raccourci du clavier: Ctrl+i
'
With ActiveWorkbook.Worksheets("Scheduling")
For Colonne = 1 To 52
.Columns(Colonne).Select
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Cells(1, Colonne), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Scheduling").Sort
.SetRange Range(Cells(2, Colonne), Cells(996, Colonne))
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next Colonne
End With
End Sub
Cela devrait vous convenir
Bonne suite
'Column("A:A") correspond a Column(1), B=2 ........
'Range("A1") correspond Cells(1,1) , B1---> Cells(1,2)
Sub Tri()
'
' Tri Macro
'
' Touche de raccourci du clavier: Ctrl+i
'
With ActiveWorkbook.Worksheets("Scheduling")
For Colonne = 1 To 52
.Columns(Colonne).Select
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Cells(1, Colonne), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Scheduling").Sort
.SetRange Range(Cells(2, Colonne), Cells(996, Colonne))
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next Colonne
End With
End Sub
Cela devrait vous convenir
Bonne suite