Bonjour,
Comment puis-je me passer d'un GoTo dans cette procédure ?
J'imagine que ce code peut être optimisé, mais j'ignore comment !
L'idée est de faire un tri automatique sur deux colonnes d'une même feuille sachant que si j'ai "A" "B" "C" et "a", ma cellule [h1] (ou [j1]) me renverra que c'est trié alors que ça ne l'est pas d'où conversion automatique des minuscules en majuscules.
Nota 1 : [h1] = =Test_Tri($H$5:$H$40)
Nota 2 : Function Test_Tri
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Function Test_Tri(liste As Range) As String Dim i& For i = 2 To liste.Count If liste(i) <> "" Then If liste(i - 1) > liste(i) Or liste(i - 1) = "" Then Test_Tri = "Liste non triée": Exit Function Next Test_Tri = "Liste triée" End Function
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 Private Sub Worksheet_Change(ByVal target As Range) Dim plg1 Dim plg2 Dim c As Range 'Dim i As Integer ' For i = 9 To 14 ' If Cells(2, i) <> "Trié" Then Range(Cells(2, i - 7), Cells(65536, i - 7).End(xlUp)).Sort Key1:=Cells(2, i - 7) ' Next Set plg1 = Intersect(target, [H5:H40]) Set plg2 = Intersect(target, [J5:J100]) '---- If plg1 Is Nothing Then GoTo suite ' Exit Sub ' Else Application.EnableEvents = False For Each c In plg1.Cells c = UCase(c) Next Application.EnableEvents = True ' End If If [h1] <> "Liste triée" Then Range("H5:H40").Sort Key1:=[h5] '---- suite: If plg2 Is Nothing Then Exit Sub Else Application.EnableEvents = False For Each c In plg2.Cells c = UCase(c) Next Application.EnableEvents = True End If '--- If [j1] <> "Liste triée" Then Range("J5:J40").Sort Key1:=[j5] End Sub
Un grand merci d'avance pour votre aide éventuelle,
Cdt
Partager