OVH Cloud OVH Cloud

Tri par macro erreur?!

2 réponses
Avatar
LeSurcitaire
Bonjour,

J'ai un classeur pour gerer un tournoi de volley. Dans une feuille
match j'ai le classement de chaque poule avec la formule
=3DSOMMEPROD((X5+Y5/100<$X$5:$X$9+$Y$5:$Y$9/100)*1)+1).
Chaque poule est en colonne Poule A K2:L6 , Poule B K9:L13 , Poule C
O2:P6 , Poule D O9:P13
J'ai donc cree une macro avec l'enregistreur de macro pour trier chaque
poule ce qui a donne la macro ci-dessous
Pour que le tri se fasse a chaque changement j'ai mis dans le code de
ma feuille ceci
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Tri
End Sub

le probl=E8me c'est que chaque fois que je change un resultat la macro
fonctionne jusqu'a ;Apply puis blocage et la je ne comprend pas j'ai
donc besion de vos lumi=E8re

Merci par avance

Ma macro

Sub Tri()
'
' Tri Macro
'
' Touche de raccourci du clavier: Ctrl+Maj+T
'
Range("K2:L6").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=3DRange("L2:L6"), _
SortOn:=3DSortOnValues, Order:=3DxlAscending,
DataOption:=3DxlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("K2:L6")
.Header =3D xlGuess
.MatchCase =3D False
.Orientation =3D xlTopToBottom
.SortMethod =3D xlPinYin
.Apply
End With
Range("K9:L13").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=3DRange("L9:L13"), _
SortOn:=3DSortOnValues, Order:=3DxlAscending,
DataOption:=3DxlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("K9:L13")
.Header =3D xlGuess
.MatchCase =3D False
.Orientation =3D xlTopToBottom
.SortMethod =3D xlPinYin
.Apply
End With
Range("O2:P6").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=3DRange("O2:O6"), _
SortOn:=3DSortOnValues, Order:=3DxlAscending,
DataOption:=3DxlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("O2:P6")
.Header =3D xlGuess
.MatchCase =3D False
.Orientation =3D xlTopToBottom
.SortMethod =3D xlPinYin
.Apply
End With
Range("O9:P13").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=3DRange("O9:O13"), _
SortOn:=3DSortOnValues, Order:=3DxlAscending,
DataOption:=3DxlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("O9:P13")
.Header =3D xlGuess
.MatchCase =3D False
.Orientation =3D xlTopToBottom
.SortMethod =3D xlPinYin
.Apply
End With
End Sub

2 réponses

Avatar
Youky
Private Sub Worksheet_Change(ByVal Target As Range)
et non
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
me semble plus approprié.
essaie de mettre une apostrophe '.Apply
non testé
Youky
"LeSurcitaire" a écrit dans le message de news:

Bonjour,

J'ai un classeur pour gerer un tournoi de volley. Dans une feuille
match j'ai le classement de chaque poule avec la formule
=SOMMEPROD((X5+Y5/100<$X$5:$X$9+$Y$5:$Y$9/100)*1)+1).
Chaque poule est en colonne Poule A K2:L6 , Poule B K9:L13 , Poule C
O2:P6 , Poule D O9:P13
J'ai donc cree une macro avec l'enregistreur de macro pour trier chaque
poule ce qui a donne la macro ci-dessous
Pour que le tri se fasse a chaque changement j'ai mis dans le code de
ma feuille ceci
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Tri
End Sub

le problème c'est que chaque fois que je change un resultat la macro
fonctionne jusqu'a ;Apply puis blocage et la je ne comprend pas j'ai
donc besion de vos lumière

Merci par avance

Ma macro

Sub Tri()
'
' Tri Macro
'
' Touche de raccourci du clavier: Ctrl+Maj+T
'
Range("K2:L6").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=Range("L2:L6"), _
SortOn:=SortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("K2:L6")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("K9:L13").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=Range("L9:L13"), _
SortOn:=SortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("K9:L13")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("O2:P6").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=Range("O2:O6"), _
SortOn:=SortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("O2:P6")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("O9:P13").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=Range("O9:O13"), _
SortOn:=SortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("O9:P13")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Avatar
LeSurcitaire
Merci beuacoup

Private Sub Worksheet_Change(ByVal Target As Range)
et non
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
me semble plus approprié.
essaie de mettre une apostrophe '.Apply
non testé
Youky
"LeSurcitaire" a écrit dans le message de ne ws:

Bonjour,

J'ai un classeur pour gerer un tournoi de volley. Dans une feuille
match j'ai le classement de chaque poule avec la formule
=SOMMEPROD((X5+Y5/100<$X$5:$X$9+$Y$5:$Y$9/100)*1)+1).
Chaque poule est en colonne Poule A K2:L6 , Poule B K9:L13 , Poule C
O2:P6 , Poule D O9:P13
J'ai donc cree une macro avec l'enregistreur de macro pour trier chaque
poule ce qui a donne la macro ci-dessous
Pour que le tri se fasse a chaque changement j'ai mis dans le code de
ma feuille ceci
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Tri
End Sub

le problème c'est que chaque fois que je change un resultat la macro
fonctionne jusqu'a ;Apply puis blocage et la je ne comprend pas j'ai
donc besion de vos lumière

Merci par avance

Ma macro

Sub Tri()
'
' Tri Macro
'
' Touche de raccourci du clavier: Ctrl+Maj+T
'
Range("K2:L6").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=Range("L2:L6"), _
SortOn:=SortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("K2:L6")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("K9:L13").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=Range("L9:L13"), _
SortOn:=SortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("K9:L13")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("O2:P6").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=Range("O2:O6"), _
SortOn:=SortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("O2:P6")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("O9:P13").Select
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Match").Sort.SortFields.Add
Key:=Range("O9:O13"), _
SortOn:=SortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Match").Sort
.SetRange Range("O9:P13")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub