Bonjour,
Comme promis voici la macro complète, si elle peut servir.
Cordialement.
Private Sub ComboBox_Sto_A_Change()
'Mise à jour de la date dernier inventaire et stock initial dans le US_Sto
Dim DL%, i%, nom$, t
DL = Sheets("STOCK").Range("B65500").End(xlUp).Row
activite = ComboBox_Sto_A.Value
TextBox_Date_Si = ""
TextBox_Si = ""
t = Sheets("STOCK").Range("A2:h" & DL)
For i = LBound(t) To UBound(t)
If t(i, 1) = activite Then
TextBox_Date_Si = t(i, 3)
TextBox_Si = t(i, 7)
End If
Next i
On Error Resume Next
Dim MaPlage As Range
Dim MaPlage2 As Range
Dim MaPlage3 As Range
Dim MaSomme As Single
Dim MaSomme2 As Single
Set MaPlage = Sheets("BASEDEDONNEES").Range("c:c")
Set MaPlage2 = Sheets("BASEDEDONNEES").Range("d:d")
Set MaPlage3 = Sheets("BASEDEDONNEES").Range("f:f")
MaSomme = Application.WorksheetFunction.SumIfs(MaPlage2, MaPlage, ComboBox_Sto_A, MaPlage3, ">" & Format(TextBox_Date_Si, "mm/dd/yyyy"))
'MaSomme2 = Application.WorksheetFunction.SumIfs(MaPlage2, MaPlage3, ">" & Format(TextBox_Date_Si, "mm/dd/yyyy"))
TextBox_Vente = MaSomme
End Sub
Private Sub CommandButton_Calcul_Click()
On Error Resume Next
TextBox_St_F.Value = (CDbl(TextBox_Si.Value) - CDbl(TextBox_Vente.Value) + CDbl(TextBox_Ach.Value) + CDbl(TextBox_Cor.Value))
End Sub
Private Sub CommandButton_Out_Click()
Dim fin As Integer
fin = MsgBox("Avez vous finaliser la validation des stocks ?", vbYesNo, "VALIDATION STOCK!")
If fin = vbOK Then
End If
Unload UserForm_Sto
End Sub
Private Sub CommandButton_Val_Sto_Click()
Dim ok As Integer
ok = MsgBox("Validez vous le nouveau stock ?", vbYesNo, "VALIDATION STOCK!")
If ok = vbNo Then
Exit Sub
End If
If ok = vbYes Then
derligne = Sheets("STOCK").Range("a456541").End(xlUp).Row + 1
Sheets("STOCK").Cells(derligne, 1) = ComboBox_Sto_A
Sheets("STOCK").Cells(derligne, 2) = CCur(TextBox_Si)
Sheets("STOCK").Cells(derligne, 3) = CDate(Date)
Sheets("STOCK").Cells(derligne, 4) = CCur(TextBox_Vente)
Sheets("STOCK").Cells(derligne, 5) = CCur(TextBox_Ach)
Sheets("STOCK").Cells(derligne, 6) = CCur(TextBox_Cor)
Sheets("STOCK").Cells(derligne, 7) = CCur(TextBox_St_F)
Sheets("STOCK").Cells(derligne, 8) = TextBox_Com
Me.TextBox_Ach = 0
Me.TextBox_Cor = 0
Me.TextBox_Vente = 0
Me.TextBox_St_F = 0
Me.TextBox_Si = 0
Me.ComboBox_Sto_A = ""
Me.ComboBox_Sto_T = ""
Me.TextBox_Com = ""
End If
End Sub
Private Sub UserForm_Initialize()
ComboBox_Sto_T.Column = Range("tb_liste[#Headers]").Value
Me.TextBoX_Date_St = Date
Me.TextBox_Ach = 0
Me.TextBox_Cor = 0
UserForm_Sto.Height = 500
UserForm_Sto.Width = 980
End Sub
Private Sub ComboBox_Sto_T_Change()
Change ComboBox_Sto_T, ComboBox_Sto_A, "tb_liste"
End Sub
Public Sub Change(CbSource As MSForms.ComboBox, CbDest As MSForms.ComboBox, nomTablo As String)
If CbSource.Value <> vbNullString Then
With CbDest
.Clear
.List = getArrayFromRange(Range(nomTablo & "[" & CbSource.Value & "]"))
End With
End If
End Sub
Private Function getArrayFromRange(Item As Range)
If WorksheetFunction.CountA(Item) > 0 Then
If Item.Cells.Count = 1 Then
Dim t(1, 1)
t(1, 1) = Item.Value
getArrayFromRange = t
Else
getArrayFromRange = Item.SpecialCells(xlCellTypeConstants).Value
End If
Else
getArrayFromRange = Array(vbNullString)
End If
End Function