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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Option Explicit
Sub TriCouleurs()
'
' TriCouleurs Macro
'
Columns("J:J").Select
ActiveWorkbook.Worksheets("Feuil6").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Feuil6").Sort.SortFields.Add Key:=Range("J1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Feuil6").Sort
.SetRange Range("J2:J3600")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("J1").Select
End Sub
Private Sub CommandButton1_Click()
Dim y As Integer
y = 2
Sheets("Feuil6").Cells(y, 1) = IIf(OptionButton1.Value = True, "Femme", "Homme")
Sheets("Feuil6").Cells(y, 2) = IIf(CheckBox1.Value = True, "Oui", "")
Sheets("Feuil6").Cells(y, 3) = IIf(CheckBox2.Value = True, "Oui", "")
Sheets("Feuil6").Cells(y, 4) = IIf(CheckBox3.Value = True, "Oui", "")
Sheets("Feuil6").Cells(y, 5) = IIf(CheckBox4.Value = True, "Oui", "")
Sheets("Feuil6").Cells(y, 6) = ComboBox1.Value
UserForm1.Hide
Call AjouterCouleur 'Ajoutera la couleur si nécessaire.
End Sub
'-------------------------------------------------------------------------------
Private Sub UserForm_Activate()
'-------------------------------------------------------------------------------
Dim y As Integer, i As Integer, TabDonnnée() As Variant
' Coche la case option 1 :
OptionButton1.Value = True
Call TriCouleurs 'Trie les données par ordre croissant.
' Charge les données pour la liste ComboBox1 :
y = 2: i = 0
While Sheets("Feuil6").Cells(y, 10) <> "" ' Boucle sur les lignes de la feuille 6.
ReDim Preserve TabDonnnée(i) ' Dimensionne le tableau.
TabDonnnée(i) = Sheets("Feuil6").Cells(y, 10) ' Charge les données en colonne J.
y = y + 1: i = i + 1 ' Passe à la ligne suivante.
Wend
ComboBox1.Clear ' Efface toutes les anciennes données de la liste.
For i = 0 To UBound(TabDonnnée()) ' Boucle sur le tableau et...
ComboBox1.AddItem TabDonnnée(i) ' alimente la liste déroulante.
Next i
End Sub |