XL 2016 Tri automatique avec appuie sur une touche

florian140001

XLDnaute Nouveau
Bonjour, j'ai réalisé un programme de tri auto mais je voudrais l'améliorer en rajoutant un appuie sur une touche (ex : t), avez vous une idée de comment faire ?


VB:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Not Intersect(Target, Range("A1:A130")) Is Nothing Then
Range("A1").Sort Key1:=Range("A2"), _
Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End If
End Sub
 

dg62

XLDnaute Barbatruc
Bonjour Florian, Zorgloub

VB:
Sub macro2()

Range("A1").Sort Key1:=Range("A2"), _
Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

End Sub

Si le code est activé par une touche ce n'est plus automatique. En transformant simplement ta procédure en macro tu peux lui affecter une combinaison de touches. Tu sélectionnes ta macro et par le bouton "Options" tu peux lui affecter la touche souhaitée.
 

job75

XLDnaute Barbatruc
Bonjour florian140001, Zorgloub, dg62,

Voyez le fichier joint et ce code dans ThisWorkbook (Alt+F11) :
VB:
Private Sub Workbook_Open()
Application.OnKey "t", Me.CodeName & ".Tri"
End Sub

Sub Tri()
With ActiveSheet.UsedRange
    .Sort .Columns(1), xlAscending, Header:=xlYes
End With
End Sub
A+
 

Pièces jointes

  • Tri(1).xlsm
    22.8 KB · Affichages: 3

Discussions similaires

Statistiques des forums

Discussions
312 078
Messages
2 085 110
Membres
102 783
dernier inscrit
Basoje