Dim nom_banq_select As String
Dim ligne As Integer
Dim i As Integer
Dim j As Integer
Dim nom_banq As String
Dim date_op As Date
Dim compt_gene As String
Dim libelle As String
Dim montant As Currency
Dim libelle2 As String
Dim justif As String
Dim solde As String
Dim non_just As Currency
Dim mont_comb As String
Dim mont_comb2 As Currency
Dim result_banq As String
Dim ligne2 As Integer
Private Sub UserForm_Initialize()
'================ AFFICHER SELECTIONNER BANQUE DANS Combobox1 ============================================
Set Ws = Sheets("Aides3")
With Me.ComboBox1
For j = 2 To Ws.Range("H" & Rows.Count).End(xlUp).Row
.AddItem Ws.Range("H" & j)
Next j
End With
TextBox14 = (0)
End Sub
'------------------------------------------------------------------------
Private Sub ComboBox1_Change() 'si ligne initiale combobox1 change ...
solde = 0
TextBox13.Value = 0
nom_banq_select = ComboBox1.Text
Sheets.Add.Name = "concord"
Set Ws = Sheets("En cours") 'Avec la feuille "En cours" fait....
justif = "x"
non_just = 0
ligne = 0
For j = 1 To Ws.Range("B" & Rows.Count).End(xlUp).Row
nom_banq = Sheets("En cours").Range("B" & j)
With Sheets("concord")
.Range("A" & j).Value = j 'Insére le numero d'index dans la colonne A feuille concord
End With
If nom_banq_select = nom_banq Then ' -- je trie sur la base des écritures non JUSTIFIEES avec la banque -----
justif = Sheets("En cours").Range("F" & j)
If justif = "," Then ' la cellule est marquée "," quand elle n'est pas justifiée avec la banque
montant = Sheets("En cours").Range("E" & j)
non_just = non_just + montant ' je cumule le montant des écritures pour affichage dans userform
ligne = ligne + 1
With Sheets("concord")
.Range("B" & j).Value = ligne 'Insére le numero d'index dans la colonne A feuille concord
End With
End If
TextBox13.Value = Format(non_just, "currency")
End If
If j = 569 Then Exit For
Next
'----------------------- Affecte le solde du comptes sélectionné dans textbox "à affiner à partir d'une variable" ---------------------------------------
With ComboBox1()
If nom_banq_select = "CAISSE" Then
solde = Sheets("En cours").Range("E" & 624)
TextBox12.Value = Format(solde, "currency") '-- Solde du compte ---
result_banq = solde - non_just
TextBox14.Value = Format(result_banq, "currency")
End If
If nom_banq_select = "COMPTE COURANT CREDIT MARITIME" Then
solde = Sheets("En cours").Range("E" & 625)
TextBox12.Value = Format(solde, "currency") '-- Solde du compte ---
result_banq = solde - non_just
TextBox14.Value = Format(result_banq, "currency")
End If
If nom_banq_select = "LIVRET CREDIT MARITIME" Then
solde = Sheets("En cours").Range("E" & 626)
TextBox12.Value = Format(solde, "currency") '-- Solde du compte ---
result_banq = solde - non_just
TextBox14.Value = Format(result_banq, "currency")
End If
If nom_banq_select = "COMPTE COURANT CREDIT MUTUEL" Then
solde = Sheets("En cours").Range("E" & 627)
TextBox12.Value = Format(solde, "currency") '-- Solde du compte ---
result_banq = solde - non_just
TextBox14.Value = Format(result_banq, "currency")
End If
If nom_banq_select = "LIVRET CREDIT MUTUEL" Then
solde = Sheets("En cours").Range("E" & 628)
TextBox12.Value = Format(solde, "currency") '-- Solde du compte ---
result_banq = solde - non_just
TextBox14.Value = Format(result_banq, "currency")
End If
End With
' ------------- si je selectionne dans la liste du combobox des non_justifiées, affiche infos de la ligne ----------------------------------
justif = "x"
Set Ws = Sheets("En cours") '------ affecte les lignes non justifié à la combobox2 par le montant
With Me.ComboBox2
For j = 8 To Ws.Range("E" & Rows.Count).End(xlUp).Row
nom_banq = Sheets("En cours").Range("B" & j)
If nom_banq_select = nom_banq Then
justif = Sheets("En cours").Range("F" & j)
If justif = "," Then .AddItem Ws.Range("E" & j)
End If
'AddItem Ws.Range("E" & j)
If j = 569 Then Exit For ' 569 dernière ligne à lire
Next j
End With
End Sub
'-----------------------------------------------------------
Private Sub ComboBox2_Change() ' si selection dans combobox2 affiche les textbox
i = 0
Set Ws = Sheets("En cours") 'Attention ce nom doit correspondre au nom de votre ONGLET
' Me.ComboBox2.ListIndex = 19 'Sheets("concord").Range("A" & j)
If Me.ComboBox2.ListIndex = -1 Then Exit Sub
If Me.ComboBox2.ListIndex > 0 Then ligne = Sheets("concord").Range("A" & j) '=============== a regler-------------
'ligne = Me.ComboBox2.ListIndex
TextBox17 = j
For i = 1 To 10
Me.Controls("TextBox" & i) = Ws.Cells(ligne, i) ' ET C'EST LA QUE JE PERDS MON INDEX DE LA FEUILLE, normal!
Next i
End Sub
'---
'================================================================================
'Correspond au programme du bouton MODIFIER
Private Sub CommandButton2_Click()
i = 0
If MsgBox("Etes-vous certain de vouloir pointer cette écriture ?", vbYesNo, "Demande de confirmation") = vbYes Then
montant = 0
If Me.ComboBox2.ListIndex = -1 Then Exit Sub 'On sort si pas de sélection
For i = 1 To 10
If Me.Controls("TextBox" & i).Visible = True Then
Ws.Cells(ligne, 6) = Me.Controls("TextBox" & 6) '--- modifie colonne justif
' ET C'EST LA QUE JE PERDS MON INDEX DE LA FEUILLE, normal!
' et je ne modifie pas la bonne ligne dans la feuille.
TextBox17 = ligne
End If
Next i
montant = TextBox13 - Sheets("En cours").Range("E" & ligne)
TextBox13.Value = Format(montant, "currency")
TextBox12.Value = Format(solde, "currency")
result_banq = TextBox12.Value - non_just
TextBox14.Value = Format(result_banq, "currency")
End If 'fin de la condition
End Sub