Autres Modification VBA

Camille123

XLDnaute Nouveau
Bonjour a tous
j'ai un fichier contenant un programme VBA dont j'aimerai qu'on m'aide a modifier la formule au niveau des enregistrements Entrée et Sortie
pour que je puisse enregistrer au delà de 50 car le fichier ne permet pas d'enregistrer cela en une transaction.
merci d'avoir pris le temps pour me lire.
Cordialement
 

Pièces jointes

  • Suivi EAU LAFI - Copie.xlsm
    130 KB · Affichages: 9

Camille123

XLDnaute Nouveau
Génial. Je tombe sur un userform vide.A ce rythme là, on n'est pas rendu. Si tu ne te décides pas à expliquer précisément le problème, je ne perdrai pas davantage mon temps.

Daniel
Bonjour Daniel merci de bien regarder voici le programme qui y figure
Private Myvar As Integer
Private ModeCréation As Boolean
Private ModeModification As Boolean
Private ModeSuppression As Boolean
Private ModeEntréeSortie As Boolean
Private MémoireModifLigneRef As Integer
Private Siècle As Byte
Private Sub CmbCréerListACommander_Click()
ChargerLaListBoxCommande
End Sub
Sub ChargerLaListBoxCommande()
Dim Cell As Range
With Worksheets("Stocks")
If .Range("A4") = "" Then
MsgBox " aucune référence dans la feuille stocks"
Exit Sub
End If
Me.ListBoxCommande.Clear
For Each Cell In .Range("A4:A" & .Range("A65536").End(xlUp).Row)
If Cell.Offset(0, 7) < Cell.Offset(0, 8) Then
Me.ListBoxCommande.AddItem
Me.ListBoxCommande.List(NbLigneUtilisée, 0) = Cell
Me.ListBoxCommande.List(NbLigneUtilisée, 1) = Cell.Offset(0, 1)
Me.ListBoxCommande.List(NbLigneUtilisée, 2) = Cell.Offset(0, 2)
Me.ListBoxCommande.List(NbLigneUtilisée, 3) = Cell.Offset(0, 3)
Me.ListBoxCommande.List(NbLigneUtilisée, 4) = Cell.Offset(0, 4)
Me.ListBoxCommande.List(NbLigneUtilisée, 5) = Cell.Offset(0, 5)
Me.ListBoxCommande.List(NbLigneUtilisée, 6) = Cell.Offset(0, 6)
Me.ListBoxCommande.List(NbLigneUtilisée, 7) = Cell.Offset(0, 9)
NbLigneUtilisée = NbLigneUtilisée + 1
End If
Next
End With
If Me.ListBoxCommande.ListCount = 0 Then
MsgBox " pas de référence à commander"
End If
End Sub

Private Sub CmbCalculConso_Click()
Dim Cell As Range
Dim Cellule As Range
Dim DateDeBut As Date
Dim DateDeFin As Date
Dim NbConsommé As Integer
Dim LigneDestination As Integer
Dim NbLigneUtilisée As Integer
TxtDateDébut.BackColor = &H80000005
TxtDateFin.BackColor = &H80000005
OptCréationJour.BackColor = &H80000005
OptDateDébutFin.BackColor = &H80000005
Sheets("Estimation Consommation").Range("A4:H5000") = ""
NbConsommé = 0
LigneDestination = 4
If Sheets("Stocks").Range("A4") = "" Then
MsgBox " aucune référence dans la feuille stocks, calcul impossible"
Exit Sub
End If

If Me.OptCréationJour = False And Me.OptDateDébutFin = False Then
MsgBox " vous n'avez pas sélectionné votre choix de calcul de la consommation"
OptCréationJour.BackColor = &H80FFFF
OptDateDébutFin.BackColor = &H80FFFF
End If
If Me.OptDateDébutFin = True Then
If Me.TxtDateDébut = "" Then
MsgBox " la date de début n'est pas documentée"
TxtDateDébut.BackColor = &H80FFFF
Exit Sub
End If
If IsDate(Me.TxtDateDébut) = False Then
MsgBox " la date de début n'est pas une date"
TxtDateDébut.BackColor = &H80FFFF
Exit Sub
End If
If Me.TxtDateFin = "" Then
MsgBox " la date de fin n'est pas documentée"
TxtDateFin.BackColor = &H80FFFF
Exit Sub
End If
If IsDate(Me.TxtDateFin) = False Then
MsgBox " la date de fin n'est pas une date"
TxtDateFin.BackColor = &H80FFFF
Exit Sub
End If
If CDate(Me.TxtDateFin) > Date Then
MsgBox " la date de fin ne peut pas ètre supérieure à la date du jour"
TxtDateFin.BackColor = &H80FFFF
Exit Sub
End If

If CDate(Me.TxtDateFin) <= CDate(Me.TxtDateDébut) Then
MsgBox " la date de fin ne peut pas ètre inférieure ou égale à la date de début"
TxtDateFin.BackColor = &H80FFFF
TxtDateDébut.BackColor = &H80FFFF
Exit Sub
End If
End If
With Sheets("Stocks")
For Each Cell In .Range("A4:A" & .Range("A65536").End(xlUp).Row)
If Me.OptCréationJour = True Then
DateDeBut = Cell.Offset(0, 11)
DateDeFin = Date
ElseIf Me.OptDateDébutFin = True Then
DateDeBut = CDate(Me.TxtDateDébut)
DateDeFin = CDate(Me.TxtDateFin)
End If
With Sheets("Mouvement")
For Each Cellule In .Range("A4:A" & .Range("A65536").End(xlUp).Row)
If Cell = Cellule And Cellule.Offset(0, 9) >= DateDeBut And Cellule.Offset(0, 9) <= DateDeFin And Cellule.Offset(0, 8) < 0 Then
NbConsommé = NbConsommé + Abs(Cellule.Offset(0, 8))
End If
Next
End With
If DateDeBut < Cell.Offset(0, 11) Then
DateDeBut = Cell.Offset(0, 11)
End If

Sheets("Estimation Consommation").Range("A" & LigneDestination) = Cell
Sheets("Estimation Consommation").Range("B" & LigneDestination) = Cell.Offset(0, 1)
Sheets("Estimation Consommation").Range("C" & LigneDestination) = Cell.Offset(0, 2)
Sheets("Estimation Consommation").Range("D" & LigneDestination) = Cell.Offset(0, 7)
Sheets("Estimation Consommation").Range("E" & LigneDestination) = DateDeBut
Sheets("Estimation Consommation").Range("F" & LigneDestination) = DateDeFin
Sheets("Estimation Consommation").Range("G" & LigneDestination) = NbConsommé
Sheets("Estimation Consommation").Range("H" & LigneDestination) = Cell.Offset(0, 11)
If NbConsommé = 0 Or DateDeFin = DateDeBut Then
Sheets("Estimation Consommation").Range("I" & LigneDestination) = "Indéfinie"
Else
Sheets("Estimation Consommation").Range("I" & LigneDestination) = Date + Int(Cell.Offset(0, 7) / (NbConsommé / (DateDeFin - DateDeBut)))
End If
Me.ListBoxConso.AddItem
Me.ListBoxConso.List(NbLigneUtilisée, 0) = Cell
Me.ListBoxConso.List(NbLigneUtilisée, 1) = Cell.Offset(0, 1)
Me.ListBoxConso.List(NbLigneUtilisée, 2) = Cell.Offset(0, 2)
Me.ListBoxConso.List(NbLigneUtilisée, 3) = Cell.Offset(0, 7)
Me.ListBoxConso.List(NbLigneUtilisée, 4) = DateDeBut
Me.ListBoxConso.List(NbLigneUtilisée, 5) = DateDeFin
Me.ListBoxConso.List(NbLigneUtilisée, 6) = NbConsommé
If NbConsommé = 0 Or DateDeFin = DateDeBut Then
Me.ListBoxConso.List(NbLigneUtilisée, 7) = "Indéfinie"
Else
Me.ListBoxConso.List(NbLigneUtilisée, 7) = Date + Int(Cell.Offset(0, 7) / (NbConsommé / (DateDeFin - DateDeBut)))
End If
NbConsommé = 0
LigneDestination = LigneDestination + 1
NbLigneUtilisée = NbLigneUtilisée + 1
Next
Sheets("Estimation Consommation").Range("A2") = "Date de mise à jour : " & Date
End With
End Sub
Private Sub CmbCreerRef_Click()
ComboRef.BackColor = &H80000005
ComboNom.BackColor = &H80000005

ModeCréation = True
CmbValiderCréation.Visible = True
CmbModifier.Visible = False
Me.ComboFamille = ""
Me.ComboRef.Style = fmStyleDropDownCombo
Me.ComboFamille.Enabled = True
Me.ComboTauxTva.Enabled = True
Me.LbDernierMouvement.Visible = False
TxtDernièreTransaction.Visible = False
Me.CmbCreerRef.Visible = False
RazeCréation
Me.ComboRef.ShowDropButtonWhen = fmShowDropButtonWhenNever
Me.ComboNom.ShowDropButtonWhen = fmShowDropButtonWhenNever
Me.ComboRef.SetFocus
End Sub
Private Sub RazeCréation()
Me.ComboTauxTva.Clear
Me.ComboRef.Clear
Me.ComboNom.Clear
Me.ComboFamille.Clear
InitDesDéroulants
Me.ComboNom.Style = fmStyleDropDownCombo
CmbEntréeSortie.Visible = False
CmbSupprimerRef.Visible = False
TxtPrixHT.Enabled = True
TxtStocksMini.Enabled = True
TxtFournisseur.Enabled = True
TxtStocks.Enabled = True
CmbValiderEntréeSortie.Visible = False
TxtStocks.Enabled = True
Me.ComboRef = ""
ComboNom = ""
TxtFournisseur = ""
TxtPrixHT = ""
TxtPrixTTC = ""
TxtStocksMini = ""
TxtDernièreTransaction = ""
Me.TxtStocks = ""
Me.ComboTauxTva = ""
End Sub
Private Sub CmbModifier_Click()
ComboRef.BackColor = &H80000005
ComboNom.BackColor = &H80000005
If Sheets("Stocks").Range("A4") = "" Then
MsgBox " Aucune donnée dans le stock, Modification impossible"
Exit Sub
End If
If ComboRef = "" Then
MsgBox " pour pouvoir modifier une référence ; il faut que la référence ou le nom soit documenté"
ComboRef.BackColor = &H80FFFF
ComboNom.BackColor = &H80FFFF
Me.ComboRef.SetFocus
Exit Sub
End If
MémoireModifLigneRef = Me.ComboRef.ListIndex + 4
ModeModification = True
CmbValiderModif.Visible = True
CmbCreerRef.Visible = False
Me.ComboNom.Style = fmStyleDropDownCombo
Me.ComboRef.Style = fmStyleDropDownCombo
Me.ComboFamille.Enabled = True
Me.ComboTauxTva.Enabled = True
Me.TxtStocks.Enabled = True
CmbEntréeSortie.Visible = False
CmbSupprimerRef.Visible = False
Me.ComboRef.Enabled = True
Me.ComboNom.Enabled = True
TxtPrixHT.Enabled = True
TxtPrixHT.Enabled = True
TxtStocksMini.Enabled = True
TxtFournisseur.Enabled = True
CmbModifier.Visible = False
End Sub

Private Sub CmbQuiiterAppli_Click()
Unload Me
End Sub

Private Sub CmbSortie2_Click()
InitAprèsTransaction
'Unload Me
End Sub

Private Sub CmbSortieCommande_Click()
'Unload Me
InitAprèsTransaction
End Sub

Private Sub CmbSupprimerRef_Click()
ComboRef.BackColor = &H80000005
ComboNom.BackColor = &H80000005
If Worksheets("Stocks").Range("A4") = "" Then
MsgBox " aucune référence dans la feuille stocks"
Exit Sub
End If
If ComboRef = "" Then
MsgBox "pour pouvoir supprimer une référence ; il faut que la référence ou le nom soit documenté"
ComboRef.BackColor = &H80FFFF
ComboNom.BackColor = &H80FFFF
Me.ComboRef.SetFocus
Exit Sub
End If
ModeSuppression = True
Réponse = MsgBox("Voulez vous vraiment supprimer la référence : " & ComboRef, vbYesNo)

If Réponse = vbYes Then
Myvar = Application.WorksheetFunction _
.Match(ComboRef, Worksheets("Stocks").Range("A1:A1000"), 0)
Sheets("Stocks").Cells(Myvar, 1).EntireRow.Delete
MsgBox " Suppression effectuée"
End If
MsgBox " Suppression effectuée"
InitAprèsTransaction
End Sub

Private Sub CmbValiderCréation_Click()
Dim FlagErreur As Boolean
FlagErreur = False
ComboRef.BackColor = &H80000005
ComboNom.BackColor = &H80000005
ComboFamille.BackColor = &H80000005
TxtEntréeSortie.BackColor = &H80000005
TxtFournisseur.BackColor = &H80000005
ComboTauxTva.BackColor = &H80000005
TxtPrixHT.BackColor = &H80000005
TxtStocksMini.BackColor = &H80000005
TxtStocks.BackColor = &H80000005
If ComboRef.ListIndex <> -1 Then
MsgBox "Cette référence existe déja, création impossible"
ComboRef.BackColor = &H80FFFF
FlagErreur = True
End If
If ComboRef = "" Then
MsgBox "Pas de référence d'indiquée"
ComboRef.BackColor = &H80FFFF
FlagErreur = True
End If
If ComboNom.ListIndex <> -1 Then
MsgBox "Ce Nom existe déja, création impossible"
ComboNom.BackColor = &H80FFFF
FlagErreur = True
End If
If ComboNom = "" Then
MsgBox "Pas de Nom d'indiqué"
ComboNom.BackColor = &H80FFFF
FlagErreur = True
End If

If Me.ComboFamille = "" Then
MsgBox "Pas de famille d'indiquée"
ComboFamille.BackColor = &H80FFFF
FlagErreur = True
End If
If TxtFournisseur = "" Then
MsgBox "Pas de fournisseur d'indiqué"
TxtFournisseur.BackColor = &H80FFFF
FlagErreur = True
End If
If Me.ComboTauxTva = "" Then
MsgBox "Pas de taux de TVA d'indiqué"
ComboTauxTva.BackColor = &H80FFFF
FlagErreur = True
End If
If TxtPrixHT = "" Then
MsgBox "Pas de prixHT d'indiqué"
TxtPrixHT.BackColor = &H80FFFF
FlagErreur = True
End If
If IsNumeric(TxtPrixHT) = False Then
MsgBox "le prixHT doit ètre numérique"
TxtPrixHT.BackColor = &H80FFFF
FlagErreur = True
End If
If TxtStocksMini = "" Then
MsgBox "Pas de stock mini d'indiqué"
TxtStocksMini.BackColor = &H80FFFF
FlagErreur = True
End If
If IsNumeric(TxtStocksMini) = False Then
MsgBox "le stock mini doit ètre numérique"
TxtStocksMini.BackColor = &H80FFFF
FlagErreur = True
End If
If TxtStocks = "" Then
MsgBox "Pas de stock d'indiqué"
TxtStocks.BackColor = &H80FFFF
FlagErreur = True
End If
If IsNumeric(TxtStocks) = False Then
MsgBox "le stock doit ètre numérique"
TxtStocks.BackColor = &H80FFFF
FlagErreur = True
End If
If FlagErreur = True Then Exit Sub
With Sheets("Stocks")
DerLigne = .Range("A65536").End(xlUp).Row
.Cells(DerLigne + 1, 1) = ComboRef
.Cells(DerLigne + 1, 2) = ComboNom
.Cells(DerLigne + 1, 3) = Me.ComboFamille
.Cells(DerLigne + 1, 4) = TxtFournisseur
.Cells(DerLigne + 1, 5) = CSng(TxtPrixHT)
.Cells(DerLigne + 1, 6) = CDbl(Me.ComboTauxTva)
.Cells(DerLigne + 1, 7) = CDbl(Me.TxtPrixTTC)
.Cells(DerLigne + 1, 8) = CDbl(Me.TxtStocks)
.Cells(DerLigne + 1, 9) = CDbl(Me.TxtStocksMini)
.Cells(DerLigne + 1, 11) = .Cells(DerLigne + 1, 7) * .Cells(DerLigne + 1, 8)
.Cells(DerLigne + 1, 12) = Date
End With
With Sheets("Mouvement")
DerLigne = .Range("A65536").End(xlUp).Row
.Range("A" & DerLigne + 1) = Me.ComboRef
.Range("B" & DerLigne + 1) = Me.ComboNom
.Range("C" & DerLigne + 1) = Me.ComboFamille
.Range("D" & DerLigne + 1) = Me.TxtFournisseur
.Range("E" & DerLigne + 1) = Round(CSng(Me.TxtPrixHT), 1)
.Range("F" & DerLigne + 1) = CDbl(Me.ComboTauxTva)
.Range("G" & DerLigne + 1) = Round(CSng(Me.TxtPrixTTC), 2)
.Range("H" & DerLigne + 1) = "Entrée"
.Range("I" & DerLigne + 1) = CInt(Me.TxtStocks)
.Range("J" & DerLigne + 1) = Date
.Range("K" & DerLigne + 1) = Round(Abs(CInt(Me.TxtStocks)) * CSng(Me.TxtPrixTTC), 2)
End With
If Me.ComboFamille.ListIndex = -1 Then
Sheets("Déroulant").Range("B" & Sheets("Déroulant").Range("B1000").End(xlUp).Row + 1) = Me.ComboFamille
End If
MsgBox "Création effectuée"
InitAprèsTransaction
End Sub
Private Sub CmbEntréeSortie_Click()
ComboRef.BackColor = &H80000005
ComboNom.BackColor = &H80000005
If Sheets("Stocks").Range("A4") = "" Then
MsgBox " Aucune donnée dans le stock , entrée/Sortie impossible"
Exit Sub
End If
If ComboRef = "" Then
MsgBox " pour pouvoir Créer une entrès/Sortie il faut que la référence ou le nom soit documenté"
ComboRef.BackColor = &H80FFFF
ComboNom.BackColor = &H80FFFF
Me.ComboRef.SetFocus
Exit Sub
End If
ModeEntréeSortie = True
If FrameEntréeSortie.Visible = False Then
FrameEntréeSortie.Visible = True
CmbSupprimerRef.Visible = False
CmbCreerRef.Visible = False
CmbModifier.Visible = False
CmbValiderEntréeSortie.Visible = True
Me.ComboFamille.Enabled = False
Me.ComboTauxTva.Enabled = False
Me.CmbEntréeSortie.Visible = False
ElseIf FrameEntréeSortie.Visible = True Then
FrameEntréeSortie.Visible = False
CmbSupprimerRef.Visible = True
CmbCreerRef.Visible = True
CmbCreerRef.Visible = True
CmbSupprimerRef.Visible = True
CmbModifier.Visible = True
CmbValiderEntréeSortie.Visible = False
Me.ComboTauxTva.Enabled = True
Me.ComboFamille.Enabled = True
End If
End Sub
Private Sub CmbSortie_Click()
InitAprèsTransaction

' Unload Me
End Sub

Private Sub CmbValiderModif_Click()
Dim FlagErreur As Boolean
FlagErreur = False
ComboRef.BackColor = &H80000005
ComboNom.BackColor = &H80000005
ComboFamille.BackColor = &H80000005
TxtEntréeSortie.BackColor = &H80000005
TxtFournisseur.BackColor = &H80000005
ComboTauxTva.BackColor = &H80000005
TxtPrixHT.BackColor = &H80000005
TxtStocksMini.BackColor = &H80000005
TxtStocks.BackColor = &H80000005
TxtStocksMini.BackColor = &H80000005

If ComboRef = "" Then
MsgBox "Pas de référence d'indiquée"
ComboRef.BackColor = &H80FFFF
FlagErreur = True
End If
If Me.ComboNom = "" Then
MsgBox "Pas de Nom d'indiqué"
ComboNom.BackColor = &H80FFFF
FlagErreur = True
End If
If Me.ComboFamille = "" Then
MsgBox "Pas de famille d'indiquée"
ComboFamille.BackColor = &H80FFFF
FlagErreur = True
End If
If TxtFournisseur = "" Then
MsgBox "Pas de fournisseur d'indiqué"
TxtFournisseur.BackColor = &H80FFFF
FlagErreur = True
End If
If Me.ComboTauxTva = "" Then
MsgBox "Pas de taux de TVA d'indiqué"
Exit Sub
End If
If TxtPrixHT = "" Then
MsgBox "Pas de prixHT d'indiqué"
TxtPrixHT.BackColor = &H80FFFF
FlagErreur = True

End If
If IsNumeric(TxtPrixHT) = False Then
MsgBox "le prixHT doit ètre numérique"
TxtPrixHT.BackColor = &H80FFFF
FlagErreur = True
End If
If TxtStocksMini = "" Then
MsgBox "Pas de stock mini d'indiqué"
TxtStocksMini.BackColor = &H80FFFF
FlagErreur = True
End If
If IsNumeric(TxtStocksMini) = False Then
MsgBox "le stock mini doit ètre numérique"
TxtStocksMini.BackColor = &H80FFFF
FlagErreur = True
End If
If TxtStocks = "" Then
MsgBox "Pas de stock d'indiqué"
TxtStocks.BackColor = &H80FFFF
FlagErreur = True
End If
If IsNumeric(TxtStocks) = False Then
MsgBox "le stock doit ètre numérique"
TxtStocks.BackColor = &H80FFFF
FlagErreur = True
End If
If FlagErreur = True Then Exit Sub
Myvar = MémoireModifLigneRef
With Sheets("Stocks")
.Cells(Myvar, 1) = ComboRef
.Cells(Myvar, 2) = ComboNom
.Cells(Myvar, 3) = Me.ComboFamille
.Cells(Myvar, 4) = TxtFournisseur
.Cells(Myvar, 5) = CSng(TxtPrixHT)
.Cells(Myvar, 6) = CDbl(Me.ComboTauxTva)
.Cells(Myvar, 7) = CDbl(Me.TxtPrixTTC)
.Cells(Myvar, 8) = CDbl(Me.TxtStocks)
.Cells(Myvar, 9) = CDbl(Me.TxtStocksMini)
.Cells(Myvar, 11) = .Cells(Myvar, 7) * .Cells(Myvar, 8)
End With
If Me.ComboFamille.ListIndex = -1 Then
Sheets("Déroulant").Range("B" & Sheets("Déroulant").Range("B1000").End(xlUp).Row + 1) = Me.ComboFamille
End If
MsgBox " Modification effectuée"
InitAprèsTransaction
End Sub

Private Sub ComboNom_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Sheets("Stocks").Range("A4") = "" And (ModeModification = False And ModeCréation = False And ModeSuppression = False And ModeEntréeSortie = False) Then
MsgBox " Aucune donnée dans le stock, Entrée/sortie ou Modification ou Suppression impossible"
Exit Sub
End If
End Sub
Private Sub ComboRef_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Sheets("Stocks").Range("A4") = "" And (ModeModification = False And ModeCréation = False And ModeSuppression = False And ModeEntréeSortie = False) Then
MsgBox " Aucune donnée dans le stock, Entrée/sortie ou Modification ou Suppression impossible"
Exit Sub
End If
End Sub

Private Sub ComboTauxTva_Change()
If IsNumeric(TxtPrixHT) = True And Me.ComboTauxTva <> "" Then
Me.TxtPrixTTC = Round(CDbl(Me.TxtPrixHT) + (CDbl(Me.TxtPrixHT) * (CSng(Me.ComboTauxTva) / 100)), 2)
End If
End Sub

Private Sub Label43_Click()

End Sub

Private Sub FrameEntréeSortie_Click()

End Sub

Private Sub ListBoxCommande_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'if Me.ListBoxCommande.List(Me.ListBoxCommande.ListIndex, 7) =
Me.ListBoxCommande.List(Me.ListBoxCommande.ListIndex, 7) = "En commande"
Myvar = Application.WorksheetFunction _
.Match(Me.ListBoxCommande.List(Me.ListBoxCommande.ListIndex, 0), Worksheets("Stocks").Range("A1:A1000"), 0)
Sheets("Stocks").Range("J" & Myvar) = "En commande"
On Error Resume Next
Myvar = 0
Myvar = Application.WorksheetFunction _
.Match(Me.ListBoxCommande.List(Me.ListBoxCommande.ListIndex, 0), Worksheets("A commander").Range("A1:A1000"), 0)
Sheets("A commander").Range("J" & Myvar) = "En commande"
On Error GoTo 0
End Sub

Private Sub ListBoxConso_Click()

End Sub

Private Sub MultiPage1_Change()
If Me.MultiPage1.Value = 0 Then
Me.ListBoxCommande.Clear
ElseIf Me.MultiPage1.Value = 1 Then
ChargerLaListBoxCommande
ElseIf Me.MultiPage1.Value = 2 Then
Me.ListBoxConso.Clear
End If
End Sub
Private Sub OptCréationJour_Click()
If Me.OptCréationJour = True Then
Me.FrameDate.Visible = False
Me.ListBoxConso.Clear
End If
End Sub
Private Sub OptDateDébutFin_Click()
If Me.OptDateDébutFin = True Then
Me.FrameDate.Visible = True
Me.TxtDateDébut.SetFocus
Me.ListBoxConso.Clear
End If
End Sub
Private Sub SpinEntréeSortie_Change()
TxtEntréeSortie = SpinEntréeSortie
If SpinEntréeSortie < 0 Then
Me.LbDestination.Visible = True
Me.TxtDestination.Visible = True
Else
Me.LbDestination.Visible = False
Me.TxtDestination.Visible = False
End If
End Sub


Private Sub TxtStocks_KeyPress(ByVal Touche As MSForms.ReturnInteger)
If InStr("0123456789", Chr(Touche)) = 0 Then Touche = 0
End Sub


' --------------- N'autorise que la saisie de chiffres
Private Sub TxtPrixHT_KeyPress(ByVal Touche As MSForms.ReturnInteger)
If InStr("0123456789,", Chr(Touche)) = 0 Then Touche = 0
End Sub

Private Sub TxtPrixHT_Change()
TxtPrixHT = Replace(TxtPrixHT, ".", ",")
If IsNumeric(TxtPrixHT) = True And Me.ComboTauxTva <> "" Then
Me.TxtPrixTTC = Round(CDbl(Me.TxtPrixHT) + (CDbl(Me.TxtPrixHT) * (CSng(Me.ComboTauxTva) / 100)), 2)
End If
End Sub
Private Sub TxtStocksMini_KeyPress(ByVal Touche As MSForms.ReturnInteger)
If InStr("0123456789,", Chr(Touche)) = 0 Then Touche = 0
End Sub

Private Sub UserForm_Initialize()
InitDesDéroulants
Me.MultiPage1.Value = 0
Me.ListBoxCommande.ColumnWidths = "60;130;70;70;70;60;70;60"
Me.ListBoxConso.ColumnWidths = "60;130;70;50;70;70;60"
DateMin = CDate("01/01/2000")
DateMax = CDate("31/12/2099")
Me.TxtDateFin = Date
End Sub
Private Sub InitDesDéroulants()
Dim Collec1 As New Collection
Dim Cell As Range, Itm As Long
With Sheets("Stocks")
If Sheets("Stocks").Range("A4") <> "" Then
For Each Cell In .Range("A4:A" & .Range("A65536").End(xlUp).Row)
Me.ComboRef.AddItem (Cell)
Next
For Each Cell In .Range("B4:B" & .Range("B65536").End(xlUp).Row)
ComboNom.AddItem (Cell)
Next
End If
End With
With Sheets("Déroulant")
If .Range("A2") <> "" Then
For Each Cell In .Range("A2:A" & .Range("A10").End(xlUp).Row)
Me.ComboTauxTva.AddItem (Cell)
Next
End If
If .Range("B2") <> "" Then
For Each Cell In .Range("B2:B" & .Range("B100").End(xlUp).Row)
Me.ComboFamille.AddItem (Cell)
Next
End If
End With
End Sub
Private Sub ComboRef_Change()
If ModeModification = True Then Exit Sub
If ComboRef <> "" Then
If ComboRef.ListIndex = -1 Then
If ModeCréation = False Then
Me.ComboNom = ""
End If
TxtFournisseur = ""
TxtPrixHT = ""
TxtPrixTTC = ""
TxtStocksMini = ""
TxtDernièreTransaction = ""
Me.ComboTauxTva = ""
Me.ComboFamille = ""
Me.TxtStocks = ""
Exit Sub
Else

Myvar = Me.ComboRef.ListIndex + 4
ChargerUserform
End If
End If
End Sub
Private Sub ComboNom_Change()
If ModeModification = True Then Exit Sub
If ComboNom <> "" Then
If ComboNom.ListIndex = -1 Then
If ModeCréation = False Then
Me.ComboRef = ""
End If
TxtFournisseur = ""
TxtPrixHT = ""
TxtPrixTTC = ""
TxtStocksMini = ""
TxtDernièreTransaction = ""
Me.ComboTauxTva = ""
Me.ComboFamille = ""
Me.TxtStocks = ""
Exit Sub
Else

Myvar = Me.ComboNom.ListIndex + 4
ChargerUserform
End If
End If
End Sub
Sub ChargerUserform()
Dim CompteurDeLigne As Long
If Sheets("Stocks").Range("A4") = "" Then Exit Sub
With Sheets("Stocks")
ComboRef = .Cells(Myvar, 1)
ComboNom = .Cells(Myvar, 2)
Me.ComboFamille = .Cells(Myvar, 3)
TxtFournisseur = .Cells(Myvar, 4)
TxtPrixHT = .Cells(Myvar, 5)
Me.ComboTauxTva = .Cells(Myvar, 6)
TxtPrixTTC = .Cells(Myvar, 7)
Me.TxtStocks = .Cells(Myvar, 8)
TxtStocksMini = .Cells(Myvar, 9)
End With
With Sheets("Mouvement")
For CompteurDeLigne = .Range("A65536").End(xlUp).Row To 1 Step -1
If .Cells(CompteurDeLigne, 1) = ComboRef Then
TxtDernièreTransaction = .Cells(CompteurDeLigne, 10)
Exit Sub
End If
Next
End With
End Sub
Private Sub CmbValiderEntréeSortie_Click()
Dim DerLigne As Long
Dim Myvar As Long
Dim FlagErreur As Boolean
FlagErreur = False
ComboRef.BackColor = &H80000005
ComboNom.BackColor = &H80000005
TxtEntréeSortie.BackColor = &H80000005
TxtDestination.BackColor = &H80000005
If FrameEntréeSortie.Visible = False Then
MsgBox " pas de transaction demandée"
Exit Sub
End If
If ComboRef = "" Then
MsgBox "Pas de référence d'indiquée"
ComboRef.BackColor = &H80FFFF
FlagErreur = True
End If
If ComboRef.ListIndex = -1 Then
MsgBox "Cette référence n'existe pas dans la base de données transaction impossible"
FlagErreur = True
End If
If ComboNom = "" Then
MsgBox "Pas de nom d'indiquée"
ComboNom.BackColor = &H80FFFF
FlagErreur = True
End If
If ComboNom.ListIndex = -1 Then
MsgBox "Ce nom n'existe pas dans la base de données transaction impossible"
FlagErreur = True
End If
If TxtEntréeSortie = "" Then
MsgBox " pas de quantité de définie"
TxtEntréeSortie.BackColor = &H80FFFF
FlagErreur = True
ElseIf CInt(Me.TxtEntréeSortie) = 0 Then
MsgBox "Demande de sortie égale à zéro , transaction impossible"
TxtEntréeSortie.BackColor = &H80FFFF
FlagErreur = True
End If




If TxtEntréeSortie <> "" Then
If CInt(Me.TxtEntréeSortie) < 0 And Me.TxtDestination = "" Then
MsgBox "En cas de sortie le destination doit ètre documentée"
TxtDestination.BackColor = &H80FFFF
FlagErreur = True
End If
If CInt(Me.TxtEntréeSortie) < 0 Then
If CInt(TxtStocks) < CInt(Abs(Me.TxtEntréeSortie)) Then
MsgBox "Impossible de sortir plus d'article qu'il n'y en a en stocks"
TxtEntréeSortie.BackColor = &H80FFFF
FlagErreur = True
End If
End If
End If
If FlagErreur = True Then Exit Sub
With Sheets("Mouvement")
DerLigne = .Range("A65536").End(xlUp).Row
.Range("A" & DerLigne + 1) = Me.ComboRef
.Range("B" & DerLigne + 1) = Me.ComboNom
.Range("C" & DerLigne + 1) = Me.ComboFamille
.Range("D" & DerLigne + 1) = Me.TxtFournisseur
.Range("E" & DerLigne + 1) = CSng(Me.TxtPrixHT)
.Range("F" & DerLigne + 1) = CDbl(Me.ComboTauxTva)
.Range("G" & DerLigne + 1) = Round(CSng(Me.TxtPrixTTC), 2)
If CInt(Me.TxtEntréeSortie) < 0 Then
.Range("H" & DerLigne + 1) = "Sortie"
.Range("L" & DerLigne + 1) = Me.TxtDestination
Else
.Range("H" & DerLigne + 1) = "Entrée"
End If
.Range("I" & DerLigne + 1) = CInt(Me.TxtEntréeSortie)
.Range("J" & DerLigne + 1) = Date
.Range("K" & DerLigne + 1) = Round(Abs(CInt(Me.TxtEntréeSortie)) * CSng(Me.TxtPrixTTC), 2)
End With

Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 8) = Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 8) + CInt(Me.TxtEntréeSortie)
If Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 8) < Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 9) And Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 10) = "" Then
Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 10) = "A commander"
End If
If Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 8) > Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 9) And Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 10) <> "" Then
Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 10) = ""
End If

Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 11) = Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 7) * Sheets("Stocks").Cells(Me.ComboRef.ListIndex + 4, 8)

RemplirLaListeACommander

MsgBox "Entrée/sortie Réalisée"
InitAprèsTransaction
End Sub



Sub InitAprèsTransaction()
Me.MultiPage1.Value = 0
ComboRef.BackColor = &H80000005
ComboNom.BackColor = &H80000005
ComboFamille.BackColor = &H80000005
TxtEntréeSortie.BackColor = &H80000005
TxtFournisseur.BackColor = &H80000005
ComboTauxTva.BackColor = &H80000005
TxtPrixHT.BackColor = &H80000005
TxtStocksMini.BackColor = &H80000005
TxtStocks.BackColor = &H80000005
Me.ComboTauxTva.Clear
Me.ComboRef.Clear
Me.ComboNom.Clear
Me.ComboFamille.Clear
Me.ComboFamille.Enabled = False
TxtFournisseur.Enabled = False
ComboTauxTva.Enabled = False

InitDesDéroulants
Me.ComboNom.Style = fmStyleDropDownCombo
CmbEntréeSortie.Visible = False
CmbSupprimerRef.Visible = False
TxtPrixHT.Enabled = False
TxtStocksMini.Enabled = True
'TxtFournisseur.Enabled = True
TxtStocks.Enabled = True
CmbValiderEntréeSortie.Visible = False
TxtStocks.Enabled = True
Me.ComboRef = ""
ComboNom = ""
TxtFournisseur = ""
TxtPrixHT = ""
TxtPrixTTC = ""
TxtStocksMini = ""
TxtDernièreTransaction = ""
Me.TxtStocks = ""
Me.ComboTauxTva = ""
ModeCréation = False
ModeModification = False
ModeSuppression = False
ModeEntréeSortie = False
MémoireModifLigneRef = 0
Me.ComboFamille = ""
Me.CmbEntréeSortie.Visible = True
Me.CmbSupprimerRef.Visible = True
Me.CmbModifier.Visible = True
Me.CmbCreerRef.Visible = True
FrameEntréeSortie.Visible = False
Me.CmbValiderCréation.Visible = False
Me.ComboRef.ShowDropButtonWhen = fmShowDropButtonWhenAlways
Me.ComboNom.ShowDropButtonWhen = fmShowDropButtonWhenAlways
SpinEntréeSortie.Value = 0
LbDernierMouvement.Visible = True
TxtDernièreTransaction.Visible = True

End Sub
Private Sub TxtDateDébut_Change()
Dim Validite As Boolean
Siècle = 20
Call ValidationDate(UFFGestionDeStocks.TxtDateDébut, DateMin, DateMax, Siècle, Validite)
If Validite = True Then
TxtDateDébut = LaDate
End If
End Sub
' --------------- N'autorise que la saisie de chiffres
Private Sub TxtDateDébut_KeyPress(ByVal Touche As MSForms.ReturnInteger)
If InStr("0123456789", Chr(Touche)) = 0 Then Touche = 0
End Sub
Private Sub TxtDateFin_Change()
Dim Validite As Boolean
Siècle = 20
Call ValidationDate(UFFGestionDeStocks.TxtDateFin, DateMin, DateMax, Siècle, Validite)
If Validite = True Then
TxtDateFin = LaDate
End If
End Sub
' --------------- N'autorise que la saisie de chiffres
Private Sub TxtDateFin_KeyPress(ByVal Touche As MSForms.ReturnInteger)
If InStr("0123456789", Chr(Touche)) = 0 Then Touche = 0
End Sub