gad311081
Messages postés53Date d'inscriptionlundi 18 février 2008StatutMembreDernière intervention31 mars 2008
-
5 mars 2008 à 23:47
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 2018
-
6 mars 2008 à 00:48
Salut à tous,
Commen le l'a conseillé Big Fish Le Vrai, je repose ma question de facon plus claire et en essayant de détailler un peu plus.
Voila, je suis entrain de constituer une gestion des stock par le biais d'Excel et de VBA.
Desciption de mon fichier d'une partie de mon fichier Excel:
Je vais prendre l'exemple de la page "Tarauds Metriques Dr-Ga" Elle constitué de - 6 tableaux de 4 colonnes (G à J)
- 37 lignes ( 14à51 / 60à97 / 106à143 / 152à189 / 198à235 / 244à281 )
Pour le moment j'ai une Userform constitué de:
- 3 CheckBox permettant de passer de 6 à 2 tableaux
- 2 CheckBox 2 à 1 tableaux
- 1 ComboBox de trouver la bonne ligne
- 1 ComboBox de trouver la bonne colonne
- 1 TextBox de spécifier la quantité
- 1 Bouton d'ajouter cette quantité dans la bonne celulle
- 1 Bouton de retirer cette quantité dans la bonne celulle
Voila j'espere que cette fois ci, c'est compréhensible....
Je souhaiterais rajouter un bouton "?" qui apres avoir spécifier toutes les caractéristiques sauf la quantité me renverrait une MsgBox m'indiquant l'etat du stock (donc la valeur de la cellule).
Est-ce que quelqu'un peut m'aider à constituer ce morceau de code?
Est-ce possible? si oui de quelle manière.
Merci
Je vous laisse mon code si cela peut aider:
Je sais cela fait un peu pavé, mais je compte de raccoucir grace aux fonctions "_", "Select Case" et "Else If" qui m'ont été conseillées par Big Fish Le vrai
Private Sub userform_initialize()
Dim Mes_Diametres As String
Dim Col As Integer
Dim Lig As Integer
Col = 5
For Lig = 12 To 131
Mes_Diametres = Sheets("Forets HSS").Cells(Lig, Col).Value
Fenetre_de_Selection_Outils.ComboBox_Diametres.AddItem Mes_Diametres
Next Lig
Dim Mes_Tailles As String
Dim Col2 As Integer
Dim Lig2 As Integer
Lig2 = 11
For Col2 = 6 To 9
Mes_Tailles = Sheets("Forets HSS").Cells(Lig2, Col2).Value
Fenetre_de_Selection_Outils.ComboBox_Tailles.AddItem Mes_Tailles
Next Col2
Dim Mes_Diametres_Nom As String
Dim Col3 As Integer
Dim Lig3 As Integer
Col3 = 5
For Lig3 = 14 To 51
Mes_Diametres_Nom = Sheets("Tarauds Metriques Dr-Ga").Cells(Lig3, Col3).Value
Fenetre_de_Selection_Outils.ComboBox_Diametres_Nom.AddItem Mes_Diametres_Nom
Next Lig3
Dim Mes_Types As String
Dim Col9 As Integer
Dim Lig9 As Integer
Lig9 = 13
For Col9 = 7 To 10
Mes_Types = Sheets("Tarauds Metriques Dr-Ga").Cells(Lig9, Col9).Value
Fenetre_de_Selection_Outils.ComboBox_Types.AddItem Mes_Types
Next Col9
End Sub
Private Sub ajouter_click()
If CheckBox_Non_Revetu.Value = True Then
Sheets("Forets HSS").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex + 6).Value = Sheets("Forets HSS").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex + 6).Value + TextBox_Quantite.Value
End If
If CheckBox_Revetu.Value = True Then
Sheets("Forets HSS Revetus").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex + 6).Value = Sheets("Forets HSS Revetus").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex + 6).Value + TextBox_Quantite.Value
End IfIf CheckBox_Non_Revetu.Value False And CheckBox_Revetu.Value False Then
MsgBox "Vous devez spécifier un type de Forêts"
End If
End Sub
Private Sub ajouter_Tarauds_Met_click()
If CheckBox_Tarauds_Met_Non_Revetu.Value True And CheckBox_Pas_Met_Dr.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 14, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 14, ComboBox_Types.ListIndex + 7).Value + TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Non_Revetu.Value True And CheckBox_Pas_Met_Ga.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 60, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 60, ComboBox_Types.ListIndex + 7).Value + TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Revetu.Value True And CheckBox_Pas_Met_Dr.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 106, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 106, ComboBox_Types.ListIndex + 7).Value + TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Revetu.Value True And CheckBox_Pas_Met_Ga.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 152, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 152, ComboBox_Types.ListIndex + 7).Value + TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Carbure.Value True And CheckBox_Pas_Met_Dr.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 198, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 198, ComboBox_Types.ListIndex + 7).Value + TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Carbure.Value True And CheckBox_Pas_Met_Ga.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 244, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 244, ComboBox_Types.ListIndex + 7).Value + TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Non_Revetu.Value False And CheckBox_Tarauds_Met_Revetu.Value False And CheckBox_Tarauds_Met_Carbure.Value = False Then
MsgBox "Vous devez spécifier obligatoirement un type de Forêts"
End If
If CheckBox_Pas_Met_Dr.Value False And CheckBox_Pas_Met_Ga.Value False Then
MsgBox "Vous devez spécifier obligatoirement le pas"
End If
If CheckBox_Pas_Met_Dr.Value True And CheckBox_Pas_Met_Ga.Value True Then
MsgBox "IMPOSSIBLE"
End If
End Sub
Private Sub Retirer_Click()
If CheckBox_Non_Revetu.Value = True Then
Sheets("Forets HSS").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex + 6).Value = Sheets("Forets HSS").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex + 6).Value - TextBox_Quantite.Value
End If
If CheckBox_Revetu.Value = True Then
Sheets("Forets HSS Revetus").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex + 6).Value = Sheets("Forets HSS Revetus").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex + 6).Value - TextBox_Quantite.Value
End If
If CheckBox_Non_Revetu.Value False And CheckBox_Revetu.Value False Then
MsgBox "Vous devez spécifier un type de Forêts"
End If
End Sub
Private Sub retirer_Tarauds_Met_click()
If CheckBox_Tarauds_Met_Non_Revetu.Value True And CheckBox_Pas_Met_Dr.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 14, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 14, ComboBox_Types.ListIndex + 7).Value - TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Non_Revetu.Value True And CheckBox_Pas_Met_Ga.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 60, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 60, ComboBox_Types.ListIndex + 7).Value - TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Revetu.Value True And CheckBox_Pas_Met_Dr.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 106, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 106, ComboBox_Types.ListIndex + 7).Value - TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Revetu.Value True And CheckBox_Pas_Met_Ga.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 152, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 152, ComboBox_Types.ListIndex + 7).Value - TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Carbure.Value True And CheckBox_Pas_Met_Dr.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 198, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 198, ComboBox_Types.ListIndex + 7).Value - TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Carbure.Value True And CheckBox_Pas_Met_Ga.Value True Then
Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 244, ComboBox_Types.ListIndex + 7).Value = Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 244, ComboBox_Types.ListIndex + 7).Value - TextBox_Quantite_Met.Value
End If
If CheckBox_Tarauds_Met_Non_Revetu.Value False And CheckBox_Tarauds_Met_Revetu.Value False And CheckBox_Tarauds_Met_Carbure.Value = False Then
MsgBox "Vous devez spécifier obligatoirement un type de Forêts"
End If
If CheckBox_Pas_Met_Dr.Value False And CheckBox_Pas_Met_Ga.Value False Then
MsgBox "Vous devez spécifier obligatoirement le pas"
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 6 mars 2008 à 00:48
salut,
je ne fais pas de VBA et n'ai pas trop regardé, juste corrigé la lisibilité du code et un peu optimisé....
j'espère que çà sera plus clair au moins pour toi ^^
Private Enum eOperator
[OP Plus]
[OP Moins]
End Enum
'
Private Sub userform_initialize()
Dim i As Integer
' Mes_Diametres :
COLONNE 5
For i = 12 To 131
Fenetre_de_Selection_Outils.ComboBox_Diametres.AddItem
_
Sheets("Forets HSS").Cells(i, 5).Value
Next i
' Mes_Tailles : LIGNE 11
For i = 6 To 9
Fenetre_de_Selection_Outils.ComboBox_Tailles.AddItem
_
Sheets("Forets HSS").Cells(11, i).Value
Next i
' Mes_Diametres_Nom : COLONNE 5
For i = 14 To 51
Fenetre_de_Selection_Outils.ComboBox_Diametres_Nom.AddItem
_
Sheets("Tarauds Metriques Dr-Ga").Cells(i, 5).Value
Next i
' Mes_Types : LIGNE
13
For i = 7 To 10
Fenetre_de_Selection_Outils.ComboBox_Types.AddItem
_
Sheets("Tarauds Metriques Dr-Ga").Cells(13, i).Value
Next i
End Sub
'
Private Sub ajouter_click()
Call ACTION_AjouterRetirer([OP Plus])
End Sub
'
Private Sub ajouter_Tarauds_Met_click()
Call ACTION_AjouterRetirer_Tarauds_Met([OP Plus])
End Sub
'
Private Sub Retirer_Click()
Call ACTION_AjouterRetirer([OP Moins])
End Sub
'
Private Sub retirer_Tarauds_Met_click()
Call ACTION_AjouterRetirer_Tarauds_Met([OP Moins])
End Sub
'
'
Private Sub ACTION_AjouterRetirer(ByVal eAction As eOperator)
' aucune CheckBox cochée, alerte
If (CheckBox_Non_Revetu.Value = False) And
(CheckBox_Revetu.Value = False) Then
MsgBox "Vous devez spécifier un type de Forêts"
Else
' CheckBox
Non_Revetu cochée, CELL += QTé
If CheckBox_Non_Revetu.Value = True
Then
With Sheets("Forets HSS").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex +
6)
If eAction = [OP Plus] Then .Value = .Value + TextBox_Quantite.Value Else .Value = .Value -
TextBox_Quantite.Value
End With
End If
' CheckBox Revetu
cochée, CELL += QTé
If CheckBox_Revetu.Value = True Then
With Sheets("Forets HSS Revetus").Cells(ComboBox_Diametres.ListIndex + 12, ComboBox_Tailles.ListIndex +
6)
If eAction = [OP Plus] Then .Value = .Value + TextBox_Quantite.Value Else .Value = .Value -
TextBox_Quantite.Value
End With
End If
End If
End Sub
'
'
Private Sub ACTION_AjouterRetirer_Tarauds_Met(ByVal
eAction As eOperator)
' LIGNE+14,
COLONNE+7, V+= QTé If CheckBox_Tarauds_Met_Non_Revetu.Value True And CheckBox_Pas_Met_Dr.Value True Then
With Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 14, ComboBox_Types.ListIndex +
7)
If eAction = [OP Plus] Then .Value = .Value + TextBox_Quantite_Met.Value Else .Value = .Value -
TextBox_Quantite_Met.Value
End With
End If
' LIGNE+60,
COLONNE+7, V+= QTé If CheckBox_Tarauds_Met_Non_Revetu.Value True And CheckBox_Pas_Met_Ga.Value True Then
With Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 60, ComboBox_Types.ListIndex +
7)
If eAction = [OP Plus] Then .Value = .Value + TextBox_Quantite_Met.Value Else .Value = .Value -
TextBox_Quantite_Met.Value
End With
End If
' LIGNE+106,
COLONNE+7, V+= QTé If CheckBox_Tarauds_Met_Revetu.Value True And CheckBox_Pas_Met_Dr.Value True Then
With Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 106, ComboBox_Types.ListIndex +
7)
If eAction = [OP Plus] Then .Value = .Value + TextBox_Quantite_Met.Value Else .Value = .Value -
TextBox_Quantite_Met.Value
End With
End If
' LIGNE+152,
COLONNE+7, V+= QTé If CheckBox_Tarauds_Met_Revetu.Value True And CheckBox_Pas_Met_Ga.Value True Then
With Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 152, ComboBox_Types.ListIndex +
7)
If eAction = [OP Plus] Then .Value = .Value + TextBox_Quantite_Met.Value Else .Value = .Value -
TextBox_Quantite_Met.Value
End With
End If
' LIGNE+198,
COLONNE+7, V+= QTé If CheckBox_Tarauds_Met_Carbure.Value True And CheckBox_Pas_Met_Dr.Value True Then
With Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 198, ComboBox_Types.ListIndex +
7)
If eAction = [OP Plus] Then .Value = .Value + TextBox_Quantite_Met.Value Else .Value = .Value -
TextBox_Quantite_Met.Value
End With
End If
' LIGNE+244,
COLONNE+7, V+= QTé If CheckBox_Tarauds_Met_Carbure.Value True And CheckBox_Pas_Met_Ga.Value True Then
With Sheets("Tarauds Metriques Dr-Ga").Cells(ComboBox_Diametres_Nom.ListIndex + 244, ComboBox_Types.ListIndex +
7)
If eAction = [OP Plus] Then .Value = .Value + TextBox_Quantite_Met.Value Else .Value = .Value -
TextBox_Quantite_Met.Value
End With
End If
'
ERREURS If CheckBox_Tarauds_Met_Non_Revetu.Value False And CheckBox_Tarauds_Met_Revetu.Value False And CheckBox_Tarauds_Met_Carbure.Value = False Then
MsgBox "Vous devez spécifier
obligatoirement un type de Forêts"
End If
If CheckBox_Pas_Met_Dr.Value = False And
CheckBox_Pas_Met_Ga.Value = False Then
MsgBox "Vous devez spécifier
obligatoirement le pas"
ElseIf (CheckBox_Pas_Met_Dr.Value = True) And
(CheckBox_Pas_Met_Ga.Value = True) And
(eAction = [OP Plus]) Then
MsgBox "IMPOSSIBLE"
End If
End Sub
pour ta question..., tu as bien expliqué le contexte mais je ne vois pas le problème, tu ne veux pas juste récupérer le contenu de la cellule si?
Je souhaiterais rajouter un bouton "?" qui apres avoir spécifier toutes
les caractéristiques sauf la quantité me renverrait une MsgBox
m'indiquant l'etat du stock (donc la valeur de la cellule)
çà serait une routine pour cocher certaines cases puis appeler le code?
si c'est çà, tu as juste à attribuer tes valeurs au checkboxes puis d'appeler le bouton_Click (ou la procédure) désiré....
<hr size="2" width="100%" /> Prenez un instant pour répondre à [infomsg_SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp