Bouton 2 macros inverses

Bonsoir à toutes et à tous,

J'essaye d'intégrer à un bouton 2 macros inverses et je n'arrive pas à trouver de réponses sur internet.

Je voudrais qu'en cliquant une première fois sur ce bouton ma liste se tri dans l'ordre alphabétique (ABCDE...) et qu'en cliquant une deuxième fois dessus, la liste se mette dans l'ordre inverse (ZYXWV...) et ainsi de suite.

Merci d'avance.

Bonsoir,

tu as les macros de tri ?

Oui,

Ordre ABCDE

Sub TriA()
'
' TriA Macro
'

'
    Range("B3:B7").Select
    ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Add Key:=Range("B3"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Feuil1").Sort
        .SetRange Range("B3:B7")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select
End Sub

Ordre ZYXWV

Sub TriZ()
'
' TriZ Macro
'

'
    Range("B3:B7").Select
    ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Add Key:=Range("B3"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Feuil1").Sort
        .SetRange Range("B3:B7")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select
End Sub

Merci.

Dans ce cas colle ça en tête d'un module!

option explicit
public ABCD as boolean

Sub Switch_ordre

If ABCD = true then

        Range("B3:B7").Select
    ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Add Key:=Range("B3"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Feuil1").Sort
        .SetRange Range("B3:B7")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select
ABCD = false

Else

Range("B3:B7").Select
    ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Add Key:=Range("B3"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Feuil1").Sort
        .SetRange Range("B3:B7")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select

ABCD = true

End If

End sub

La fin du code que tu as posté est pour moi ? ^^

Haha! Non pas du tout, je me suis mélangé dans mes copier coller!

J'ai édité le code! ça devrait aller maintenant!

^^

Je te remercie pour ta réponse, bonne soirée à toi

Bonsoir Arkaza, L-Yann,

voici ce que j'ai compris de ta demande... un petit bouton...

Private Sub cmdTri_Click()
'
ISort = IIf(Feuil1.OLEObjects("cmdTri").Object.Caption = "Tri +", xlAscending, xlDescending)
Feuil1.OLEObjects("cmdTri").Object.Caption = IIf(ISort = xlAscending, "Tri -", "Tri +")
Range("B3:B7").Sort key1:=Range("B3"), order1:=ISort
'
End Sub

A+

16triparadoxal.xlsm (18.48 Ko)

Oui c'est cela aussi, merci

Tant mieux!

A+

Rechercher des sujets similaires à "bouton macros inverses"