Option Explicit
Public Sens As Integer
Dim Tablo()
Private Sub UserForm_Initialize()
Tablo = [Designations].Value
IniCombo
End Sub
Private Sub ComboBox1_Change()
If ComboBox1.ListIndex = -1 Then
Efface
Exit Sub
End If
TextBox1 = Tablo(ComboBox1.ListIndex + 1, 2)
End Sub
Private Sub CommandButton1_Click()
Dim X As Long
If TextBox2 = "" Then Exit Sub
X = ComboBox1.ListIndex + 1
With ListBox1
.AddItem ComboBox1
.List(.ListCount - 1, 1) = TextBox2
.List(.ListCount - 1, 2) = X
End With
Tablo(X, 2) = Tablo(X, 2) - Val(TextBox2)
IniCombo
Efface
End Sub
Private Sub CommandButton2_Click()
Dim I As Long, L As Long
With ListBox1
For I = 0 To .ListCount - 1
If .Selected(I) Then ' (pourquoi ?)
L = .List(I, 2)
Tablo(L, 2) = Tablo(L, 2) + Val(.List(I, 1)) * Sens
.RemoveItem I
Efface
IniCombo
End If
Next
End With
End Sub
Private Sub CommandButton3_Click()
ListBox1.Clear
Tablo = [Designations].Value
Efface
IniCombo
End Sub
Private Sub CommandButton4_Click()
Dim I As Long, DL As Long
If ListBox1.ListCount = 0 Then Exit Sub
For I = 0 To ListBox1.ListCount - 1
With Sheets(Me.Caption)
DL = .[A65000].End(xlUp).Row + 1
.Unprotect "flappy"
.Cells(DL, 1) = ListBox1.List(I, 0)
.Cells(DL, 2) = ListBox1.List(I, 1)
.Cells(DL, 3) = VBA.Date
.Protect "flappy"
End With
With Pharmacie 'attention c'est le codename de la feuille
.Unprotect "flappy"
.Cells(ListBox1.List(I, 2) + 3, 2) = _
.Cells(ListBox1.List(I, 2) + 3, 2) + Val(ListBox1.List(I, 1)) * Sens
.Protect "flappy"
End With
Next
Unload Me
End Sub
Private Sub CommandButton5_Click()
Unload Me
End Sub
Private Sub TextBox2_Change()
If Val(TextBox2) > Val(TextBox1) Then TextBox2 = ""
End Sub
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr(1, "0123456789", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Sub IniCombo()
ComboBox1.List = Tablo
End Sub
Sub Efface()
TextBox1 = ""
TextBox2 = ""
ComboBox1 = ""
End Sub