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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
| 'Pour le formulaire
Private Sub UserForm_Initialize()
ComboBox2.RowSource = ("l_tiers")
ComboBox3.RowSource = ("l_categories")
ComboBox4.RowSource = ("l_postes")
End Sub
'Pour Ajouter données dans listes "Catégories"
Private Sub ComboBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Cpt As String
Dim Ci As Range
Dim Der_Ligne As Integer
Cpt = ComboBox2 ' recherche la pièce début
'recherche du cpt dans la colonne E
Set Ci = Sheets("Catégories").Range("l_tiers").Find(What:=Cpt, LookAt:=xlWhole)
'Si le cpt n'existe pas alors on vas à la première ligne vide
'on lui donne le nom du cpt et on sélectionne la cellule
If Ci Is Nothing Then
Select Case MsgBox("Voulez vous ajouter ce tiers à la liste ?", vbYesNo Or vbMsgBoxRight Or vbDefaultButton1 Or vbQuestion, "Nouveau tiers !")
Case vbYes
Der_Ligne = Sheets("Catégories").Range("E65536").End(xlUp).Row + 1
Sheets("Catégories").Cells(Der_Ligne, 5) = ComboBox2
ComboBox2.RowSource = ("l_tiers") ' on charge le combobox et on classe
Sheets("Catégories").Select
Columns("E:E").Select
ActiveWorkbook.Worksheets("Catégories").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Catégories").Sort.SortFields.Add Key:=Range("E1") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Catégories").Sort
.SetRange Range("E2:E65536")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Bilan").Select
Case vbNo
End Select
Else
End If
End Sub
Private Sub ComboBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Cpt As String
Dim Ci As Range
Dim Der_Ligne As Integer
Cpt = ComboBox3 ' recherche la pièce début
'recherche du cpt dans la colonne A
Set Ci = Sheets("Catégories").Range("l_categories").Find(What:=Cpt, LookAt:=xlWhole)
'Si le cpt n'existe pas alors on vas à la première ligne vide
'on lui donne le nom du cpt et on sélectionne la cellule
If Ci Is Nothing Then
Select Case MsgBox("Voulez vous ajouter cette catégorie à la liste ?", vbYesNo Or vbMsgBoxRight Or vbDefaultButton1 Or vbQuestion, "Nouvelle catégorie !")
Case vbYes
Der_Ligne = Sheets("Catégories").Range("a65536").End(xlUp).Row + 1
Sheets("Catégories").Cells(Der_Ligne, 1) = ComboBox3
ComboBox3.RowSource = ("l_categories") ' on charge le combobox et on classe
Sheets("Catégories").Select
Columns("A:A").Select
ActiveWorkbook.Worksheets("Catégories").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Catégories").Sort.SortFields.Add Key:=Range("A1") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Catégories").Sort
.SetRange Range("A2:A65536")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Bilan").Select
Case vbNo
End Select
Else
End If
End Sub
Private Sub ComboBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Cpt As String
Dim Ci As Range
Dim Der_Ligne As Integer
Cpt = ComboBox4 ' recherche la pièce début
'recherche du cpt dans la colonne C
Set Ci = Sheets("Catégories").Range("l_postes").Find(What:=Cpt, LookAt:=xlWhole)
'Si le cpt n'existe pas alors on vas à la première ligne vide
'on lui donne le nom du cpt et on sélectionne la cellule
If Ci Is Nothing Then
Select Case MsgBox("Voulez vous ajouter ce poste à la liste ?", vbYesNo Or vbMsgBoxRight Or vbDefaultButton1 Or vbQuestion, "Nouveau poste !")
Case vbYes
Der_Ligne = Sheets("Catégories").Range("c65536").End(xlUp).Row + 1
Sheets("Catégories").Cells(Der_Ligne, 3) = ComboBox4
ComboBox4.RowSource = ("l_postes") ' on charge le combobox et on classe
Sheets("Catégories").Select
Columns("C:C").Select
ActiveWorkbook.Worksheets("Catégories").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Catégories").Sort.SortFields.Add Key:=Range("C1") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Catégories").Sort
.SetRange Range("C2:C65536")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Bilan").Select
Case vbNo
End Select
Else
End If
End Sub
'pour afficher textbox 1 en euro
Private Sub TextBox1_Enter()
TextBox1.Text = ValEuros(TextBox1.Text)
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = AutoriseCaract(KeyAscii)
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Text = ValEuros(TextBox1.Text, True)
End Sub
Private Function ValEuros(ByVal T As String, Optional E As Boolean) As Variant
If E Then
ValEuros = Format(CCur("0" & Trim(T)), "0.00 ")
Else
ValEuros = CCur("0" & Trim(Replace(T, "", "")))
If ValEuros = 0 Then ValEuros = ""
End If
End Function
Private Function AutoriseCaract(ByVal C As Integer) As Integer
Select Case C
Case 46 'le point en virgule
AutoriseCaract = 44
Case 44, 48 To 57 'les chiffres et la virgule
AutoriseCaract = C
End Select
End Function
'Pour le bouton SAISIR
Private Sub CommandButton1_Click()
Dim l As Integer
If MsgBox("Confirmez-vous cette saisi ?", vbYesNo, "Demande de confirmation dajout") = vbYes Then
'Saisi vers Compte courant CA
l = Sheets("Relevé").Range("a65536").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement à la première ligne de tableau non vide
Sheets("Relevé").Range("a" & l).Value = Calendar1
Sheets("Relevé").Range("b" & l).Value = ComboBox2
Sheets("Relevé").Range("c" & l).Value = ComboBox3
Sheets("Relevé").Range("d" & l).Value = ComboBox4
Sheets("Relevé").Range("h" & l).Value = TextBox3
'Variable Recette / Dépense
If OptionButton1.Value = True Then
Sheets("Relevé").Range("f" & l).Value = ValEuros(TextBox1.Text)
End If
If OptionButton2.Value = True Then
Sheets("Relevé").Range("e" & l).Value = ValEuros(TextBox1.Text)
End If
End If
End Sub
'Pour le bouton Quitter
Private Sub CommandButton3_Click()
'Tri descendant des feuilles
With Worksheets("Relevé").Sort
.SortFields.Clear
.SortFields.Add Key:=Sheets("Relevé").Range("A4"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SetRange Sheets("Relevé").Range("A4:H65536")
.Header = xlYes
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Quitter
Unload Me
End Sub |
Partager