[COLOR="RoyalBlue"]Option Explicit[/COLOR] [COLOR="SeaGreen"]'Oblige à déclarer toutes les variables[/COLOR]
[COLOR="SeaGreen"]'Procédure pour la Liste de choix "Nom des Clients "[/COLOR]
[COLOR="RoyalBlue"]Private[/COLOR] A [COLOR="RoyalBlue"]As[/COLOR] Range [COLOR="SeaGreen"]'Déclare la variable A pour la "plage client"[/COLOR]
[COLOR="RoyalBlue"] Private[/COLOR] cel [COLOR="RoyalBlue"]As[/COLOR] Range [COLOR="SeaGreen"]'Déclare la variable Cel pour le "Nom Client"[/COLOR]
[COLOR="SeaGreen"]'Déclare la varible X[/COLOR]
[COLOR="Blue"]Dim[/COLOR] X [COLOR="Blue"]As Byte[/COLOR]
[COLOR="SeaGreen"]'Déclare les variables AS INTEGER[/COLOR]
[COLOR="Blue"]Dim[/COLOR] L [COLOR="Blue"]As Integer,[/COLOR] [COLOR="Blue"]LNomClient[/COLOR] [COLOR="Blue"]As Integer[/COLOR]
[COLOR="SeaGreen"]'Déclare la variable Lig[/COLOR]
[COLOR="RoyalBlue"]Dim [/COLOR]Lig[COLOR="RoyalBlue"] As Long[/COLOR]
[COLOR="Green"] 'Déclare la variable flag[/COLOR]
[COLOR="Blue"]Dim[/COLOR] flag [COLOR="Blue"]As [/COLOR]Boolean
[COLOR="SeaGreen"]'Déclare la varible colonne[/COLOR]
[COLOR="Blue"] Dim[/COLOR] col [COLOR="Blue"]As Byte[/COLOR]
[COLOR="Blue"]Private Sub[/COLOR] UserForm_Initialize()
[COLOR="SeaGreen"]'Initialise à l'ouvertue de l'UserFrom
'Création de la Liste de Choix"Nom des Clients
'On remplit la liste des Noms
'Définit la variable A[/COLOR]
[COLOR="Blue"]Set[/COLOR] A = Range("A12:A" & Range("A65536").End(xlUp).Row)
[COLOR="Teal"]'On boucle sur toutes les cellules de la plage A[/COLOR]
[COLOR="Blue"] For X [/COLOR]= 1 [COLOR="Blue"]To [/COLOR]42
col = 1 + 43[COLOR="Green"] 'Détermine le choix des colonnes[/COLOR]
[COLOR="Green"]'Redéfinit la vériable A et l'unie avec la dernière colonnes du tableau[/COLOR]
[COLOR="RoyalBlue"] Set [/COLOR]A = Application.Union(A, Range(Cells(43, col), Cells(65536, col).End(xlUp)))
[COLOR="Green"]'Sort de la boucle[/COLOR]
[COLOR="Blue"] Next X[/COLOR]
[COLOR="Green"]'Alimentation de la listbox[/COLOR]
[COLOR="Blue"]With[/COLOR] Me.NomClient
.Clear
.ColumnCount = 3
.ColumnWidths = "50;0;0"
.Style = fmStyleDropDownList
[COLOR="Blue"]For Each [/COLOR]cel [COLOR="Blue"]In[/COLOR] A [COLOR="Green"]'boucle sur toutes les cellules Cel de la plage A[/COLOR]
.AddItem (cel.Value) [COLOR="Green"]'ajout le nom du client(en colonne 0 de la listbox)[/COLOR]
[COLOR="Green"]'Ajout le montantGlobal (en colonne 1 de la listbox)
'Prend en compte la listbox et ajout de la somme[/COLOR]
.Column(1, .ListCount - 1) = cel.Offset(0, 1).Value
[COLOR="Green"] 'Mets au format monaitère de la somme affichée dans la textbox[/COLOR]
.Column(1, .ListCount - 1) = Format(.Column(1, .ListCount - 1), "#,##0.00 €")
[COLOR="Green"]'Mémorise le numéro de ligne[/COLOR]
.List(.ListCount - 1, .ColumnCount - 1) = cel.Row
[COLOR="Green"] 'fin de la prise en compte de la listbox[/COLOR]
[COLOR="Blue"]Next [/COLOR]cel [COLOR="Green"]'prochaine cellule Cel de la listbox[/COLOR]
[COLOR="Blue"]End With[/COLOR]
[COLOR="Green"]'Création pour les "Date de Saisies"
'Affiche la date de saisie[/COLOR]
DateSaisie.Value = Sheets("SAISIE1").Range("B8").Value
[COLOR="Blue"]Exit Sub[/COLOR]
[COLOR="Blue"]End Sub[/COLOR]
[COLOR="Blue"]Private Sub[/COLOR] NomClient_Change() [COLOR="Green"]'On récupère le combobox1 "NomClient" pour modification[/COLOR]
[COLOR="Green"]'Définit la variable LNomClient[/COLOR]
LNomClient = Cells.Find(NomClient.Value, LookIn:=xlValues).Row
Me.MontantGlobal.Value = Cells(LNomClient, 43).Value
[COLOR="Green"]'Mise au format de la TextBox1 "MontantGlobal"[/COLOR]
Me.MontantGlobal.Value = Format(Me.MontantGlobal, "#,##0.00 €")
[COLOR="Green"]'Définit la variable Lig[/COLOR]
Lig = CLng(NomClient.List(NomClient.ListIndex, (NomClient.ColumnCount - 1)))
[COLOR="Green"]'Parametrage des autres ComboBox[/COLOR]
NFacture.Clear
NAnFacture1.Clear
NAnFacture2.Clear
NFactureUnique.Clear
[COLOR="Green"]'Creé une boucle dans le tableau à partir de la colonne 16 pour le choix du N°de facture[/COLOR]
[COLOR="Blue"]For[/COLOR] X = coldep [COLOR="Blue"]To[/COLOR] colder [COLOR="Blue"]Step[/COLOR] pas
[COLOR="Blue"] With [/COLOR]NFacture
.AddItem Cells(Lig, X)
.List(.ListCount - 1, 1) = Cells(Lig, X).Offset(0, 1)
[COLOR="Blue"]If [/COLOR]Cells(Lig, X).Offset(0, 1).Font.ColorIndex = 5 Then [COLOR="Green"]'Affect une couleur au départ[/COLOR]
[COLOR="Green"] 'La facture à déjà étée payée[/COLOR]
.List(.ListCount - 1, 2) = "Payer"
[COLOR="Blue"] Else[/COLOR]
[COLOR="Green"]'la facture est dûe[/COLOR]
.List(.ListCount - 1, 2) = ""
[COLOR="RoyalBlue"] End If
End With[/COLOR]
[COLOR="RoyalBlue"] With[/COLOR] NAnFacture1
.AddItem Cells(Lig, X).Offset(0, off1)
.List(.ListCount - 1, 1) = Cells(Lig, X).Offset(0, off1 + 1)
[COLOR="RoyalBlue"]If [/COLOR]Cells(Lig, X).Offset(0, off1 + 1).Font.ColorIndex = 5 Then
[COLOR="Green"] 'La facture à déjà étée payée[/COLOR]
.List(.ListCount - 1, 2) = "Payer"
[COLOR="RoyalBlue"] Else[/COLOR]
[COLOR="Green"] 'la facture est dûe[/COLOR]
.List(.ListCount - 1, 2) = ""
[COLOR="RoyalBlue"] End If
End With[/COLOR]
[COLOR="RoyalBlue"] With[/COLOR] NAnFacture2
.AddItem Cells(Lig, X).Offset(0, off2)
.List(.ListCount - 1, 1) = Cells(Lig, X).Offset(0, off2 + 1)
[COLOR="RoyalBlue"] If [/COLOR]Cells(Lig, X).Offset(0, off2 + 1).Font.ColorIndex = 5 Then
[COLOR="Green"] 'La facture à déjà étée payée[/COLOR]
.List(.ListCount - 1, 2) = "Payer"
[COLOR="Blue"] Else[/COLOR]
[COLOR="Green"] 'la facture est dûe[/COLOR]
.List(.ListCount - 1, 2) = ""
[COLOR="Blue"] End If
End With[/COLOR]
[COLOR="Blue"] With[/COLOR] NFactureUnique
.AddItem Cells(Lig, X).Offset(0, off3)
.List(.ListCount - 1, 1) = Cells(Lig, X).Offset(0, off3 + 1)
[COLOR="Blue"][COLOR="Blue"] If[/COLOR][/COLOR] Cells(Lig, X).Offset(0, off3 + 1).Font.ColorIndex = 5 Then
[COLOR="SeaGreen"] 'La facture à déjà étée payée[/COLOR]
.List(.ListCount - 1, 2) = "Payer"
[COLOR="Blue"] Else[/COLOR]
[COLOR="SeaGreen"] 'la facture est dûe[/COLOR]
.List(.ListCount - 1, 2) = ""
[COLOR="Blue"] End If
End With[/COLOR]
[COLOR="Blue"]Next X[/COLOR]
[COLOR="Blue"]End Sub[/COLOR]
[COLOR="Blue"]Private Sub[/COLOR] NFacture_Change() [COLOR="Green"]'au changement dans la listbox[/COLOR]
[COLOR="Blue"]Call[/COLOR] Combochange(Me.NFacture, Me.MonFacture, Me.ToggleButton1)
[COLOR="Blue"]End Sub[/COLOR]
[COLOR="Blue"]Private Sub[/COLOR] NAnFacture1_Change() [COLOR="Green"]'au changement dans la listbox[/COLOR]
[COLOR="Blue"]Call [/COLOR]Combochange(Me.NAnFacture1, Me.MonAnFacture1, Me.ToggleButton2)
[COLOR="Blue"]End Sub[/COLOR]
[COLOR="Blue"]Private Sub[/COLOR] NAnFacture2_Change() [COLOR="Green"]'au changement dans la listbox[/COLOR]
[COLOR="Blue"]Call [/COLOR]Combochange(Me.NAnFacture2, Me.MonAnFacture2, Me.ToggleButton3)
[COLOR="Blue"]End Sub[/COLOR]
[COLOR="Blue"]Private Sub[/COLOR] NFactureUnique_Change() [COLOR="Green"]'au changement dans la listbox[/COLOR]
[COLOR="Blue"]Call[/COLOR] Combochange(Me.NFactureUnique, Me.MonFactureUnique, Me.ToggleButton4)
[COLOR="Blue"]End Sub[/COLOR]
[COLOR="Blue"]Private Sub[/COLOR] Combochange(Cb As MSForms.ComboBox, tb As MSForms.TextBox, TG As MSForms.ToggleButton)
[COLOR="Blue"]If[/COLOR] Cb.ListIndex = -1 [COLOR="Blue"]Then Exit Sub[/COLOR]
[COLOR="Blue"]If[/COLOR] Cb.List(Cb.ListIndex, 2) = "Payer" [COLOR="Blue"]Then[/COLOR]
tb.ForeColor = &HFF0000
TG = True
[COLOR="Blue"]Else[/COLOR]
tb.ForeColor = &HC0&
TG = False
[COLOR="Blue"]End If[/COLOR]
tb.Value = Format(CCur(Cb.List(Cb.ListIndex, 1)), "#,##0.00 €")
[COLOR="Blue"]End Sub[/COLOR]