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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| Private Sub UserForm_Initialize()
Dim f As Worksheet
Dim i As Integer
Dim Derlig As Integer
Dim j%, k%, temp$, liste() As String
Set f = ThisWorkbook.Sheets("Formulaire")
With f
Derlig = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To Derlig
Me.ComboBox1.AddItem Range("B" & i).Value 'On attribue les valeurs de la colonne B au contrôle Recherche
Next i
End With
Set f = Nothing 'Pour détruire la variable objet workbook
ReDim liste(0)
With Range("B2", Range("B1048576").End(xlUp)) 'Cette partie du code sert à trier les valeurs dans le contrôle Recherche mais pas sur la feuille !!
For j = 1 To .Rows.Count
If .Cells(j, 1).Value <> "" Then
ReDim Preserve liste(k)
liste(k) = .Cells(j, 1).Value
k = k + 1
End If
Next j
End With
For j = 0 To UBound(liste) - 1
For k = j + 1 To UBound(liste)
If liste(k) < liste(j) Then
temp = liste(j)
liste(j) = liste(k)
liste(k) = temp
End If
Next k
Next j
ComboBox1.List = liste
ComboBox2.List() = Array("", "Mr", "Mme", "Mlle") 'On atribue des valeurs initiales à la liste déroulante Civilité
End Sub
Private Sub CommandButton2_Click() 'Bouton Ajouter
Dim numero_lig As Integer
Sheets("Formulaire").Select
numero_lig = ComboBox1.ListIndex + 2
If ComboBox1.Value = "" Then
MsgBox ("Veuillez choisir un champs dans la recherche !")
ElseIf TextBox1.Value = "" Then
MsgBox ("Veuillez d'abord cliquer sur le bouton Aller à !")
Else
Cells(numero_lig, 1) = ComboBox2.Value
Cells(numero_lig, 2) = TextBox1.Value
Cells(numero_lig, 3) = TextBox2.Value
End If
End Sub
Private Sub CommandButton3_Click() 'Bouton supprimer
n_ligne = ComboBox1.ListIndex + 2 'Pour déterminer le numéro de ligne, à partir de 2 car les données commencent à la 2ème ligne
If ComboBox1.Value <> "" Then 'Cette partie du code est nécessaire pour éviter de supprimer un contact qui a
'le même nom que celui que vous souhaitez supprimer car dans la recherche, seuls les noms s'affichent
If TextBox1.Value = "" Then
MsgBox ("Cliquez d'abord sur le bouton Aller à!!")
Else
Rows(n_ligne).Delete
ComboBox2.Value = Cells(n_ligne, 1)
TextBox1.Value = Cells(n_ligne, 2)
TextBox2.Value = Cells(n_ligne, 3)
End If
Else
MsgBox ("Veuillez choisir un champs dans la recherche !!")
End If
End Sub |
Partager