Option Explicit
Dim Ws As Worksheet
Dim SelectedIndex As Integer
Public WithEvents TxtB As MSForms.TextBox
Dim cls(1 To 15) As New Modifier
Private Sub Quitter_Click()
Unload Me 'Ferme le Formulaire
Accueil.Show 0
End Sub
Private Sub TxtB_change()
Dim i%, mem As Double
If Right(TxtB.Value, 1) = "." Then TxtB.Value = Replace(TxtB.Value, ".", ",")
For i = 2 To 13
If Modifier.Frame1.Controls("TextBox" & i).Value <> "" Then
mem = mem + Modifier.Frame1.Controls("TextBox" & i).Value
End If
Next i
Modifier.Frame1.TextBox14 = mem
End Sub
Private Sub UserForm_Activate()
Dim J As Long
Dim i As Integer, ctrl, a&
ComboBox2.ColumnCount = 1 'Pour la liste Civilité
ComboBox2.List() = Array("Civilité", "Mr", "Mme")
Set Ws = Sheets("Controle") 'Correspond au nom de l'onglet dans le fichier Excel
With Me.ComboBox1
For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
.AddItem Ws.Range("C" & J) & " - " & Format(Ws.Range("A" & J), "0# ## ## ## ##")
Next J
End With
For Each ctrl In Me.Frame1.Controls
If TypeName(ctrl) = "TextBox" And ctrl.Name <> "TextBox14" Then
a = a + 1: Set cls(a).TxtB = ctrl
End If
Next
End Sub
Private Sub ComboBox1_Change()
Dim Ligne As Long
Dim i As Integer
SelectedIndex = Me.ComboBox1.ListIndex
If Me.ComboBox1.ListIndex = -1 Then
ComboBox2.ListIndex = -1
For i = 1 To 14
Me.Controls("TextBox" & i) = ""
Next i
Else
Ligne = Me.ComboBox1.ListIndex + 2
ComboBox2 = Ws.Cells(Ligne, "B")
For i = 1 To 14
Me.Controls("TextBox" & i) = Ws.Cells(Ligne, i + 2)
Next i
End If
End Sub
Private Sub Valider_Click()
'Correspond au programme du bouton Modifier
Dim Ligne As Long
Dim i As Integer
Dim L As Long
If MsgBox("Etes-vous certain de vouloir mofifier la fiche?", vbYesNo, "Demande de confirmation") = vbYes Then
If SelectedIndex = -1 Then Exit Sub
Ligne = SelectedIndex + 2
Ws.Cells(Ligne, "B") = ComboBox2
For i = 1 To 14
If Me.Controls("TextBox" & i).Visible = True Then
Ws.Cells(Ligne, i + 2) = Me.Controls("TextBox" & i)
End If
Range("D" & Ligne).Value = CDbl(TextBox2.Value)
Range("E" & Ligne).Value = CDbl(TextBox3.Value)
Range("F" & Ligne).Value = CDbl(TextBox4.Value)
Range("G" & Ligne).Value = CDbl(TextBox5.Value)
Range("H" & Ligne).Value = CDbl(TextBox6.Value)
Range("I" & Ligne).Value = CDbl(TextBox7.Value)
Range("J" & Ligne).Value = CDbl(TextBox8.Value)
Range("K" & Ligne).Value = CDbl(TextBox9.Value)
Range("L" & Ligne).Value = CDbl(TextBox10.Value)
Range("M" & Ligne).Value = CDbl(TextBox11.Value)
Range("N" & Ligne).Value = CDbl(TextBox12.Value)
Range("O" & Ligne).Value = CDbl(TextBox13.Value)
Range("P" & Ligne).Formula = "=SUM(D" & Ligne & ":O" & Ligne & ")"
Next i
End If
End Sub