Formulaire de saisie d'un fichier Excel en VBA
Bonjour,
J'ai un tableau qui sert de base de données ou je souhaiterais créer un formulaire de saisie afin que n'importe quel utilisateurs puissent saisir/consulter/modifier une commande.
Pour l'instant j'arrive à afficher dans une combobox la liste de mes numéros de commande.
Mais je n'arrive pas a faire afficher dans mes textbox les données de la commande correspondante tel que le nom du client par exemple.
Cela fait maintenant un bon moment que je cherche sans succès.
Je joins une ébauche de mon fichier réel (qui comporte pour l'original un planning et divers onglets de traitement des données) pour que vous puissiez comprendre un peu mieux ce que je raconte.
A la suite de ça j'aimerais que à les boutons nouveau et modifier puisse créer ou modifier une commande.
Cela fait très longtemps que je n'ai pas travailler sur du codage j'ai juste des bases
Merci d'avance pour toutes l'aide aussi petite soit elle que vous pourrez m'apportez car je galère vraiment.
Dans l'attente de vous lire.
Bonne journée.
Private Sub UserForm_Initialize()
Sheets("BDD").Activate
CB_CDE.Clear
For i = 1 To 255 ' Liste les numeros de commandes
CB_CDE.AddItem Cells(i, 1)
Next
End SubPrivate Sub CB_CDE_Change()
Dim commande As String
Dim Tx_NOM As String
Dim table_BDD As Range
Dim nb_ligne, ind As Integer
commande = CB_CDE.Value
MsgBox (commande)
Set table_BDD = Worksheets("BDD").Range("A1:BF255")
nb_ligne = table_BDD.Rows.Count
For ind = 1 To nb_ligne
cde_donnees.Value = Application.WorksheetFunction.VLookup(ind, table_BDD, 1)
If cde - donnees = commande Then
Tx_NOM = Application.WorksheetFunction.VLookup(ind, table_BDD, 2)
CB_MOIS = Application.WorksheetFunction.VLookup(ind, table_BDD, 3)
End If
Next
End Sub
bonjour,
Et le fichier il est OU le fichier ?
A+
galopin01 a écrit :bonjour,
Et le fichier il est OU le fichier ?
A+
Échec de téléchargement
Je viens d'essayer ce bout de code qui pour l'instant m'affiche quelque chose dans ma textbox mais c'est seulement la 1ere ligne de ma deuxième colonne même si je change de commande dans ma combobox.
Private Sub CB_CDE_Change()
Dim no_colonne, no_ligne As Integer
no_ligne = CB_CDE.ListIndex
If no_ligne > 0 Then
Tx_NOM.Text = Cells(Ligne + 1, 2)
End If
End SubUne idée de ce que je doit modifier pour avoir le bon numéro de ligne ?
Merci
Voici un code qui fonctionne si ca peut aider
Private Sub CB_CDE_Change()
Dim no_colonne, no_ligne, no_ligneEND, nb_CB As Integer
Dim DATE1, DATE2, DATE3, DATE4, DATE5 As Variant
no_ligne = CB_CDE.ListIndex + 3
no_ligneEND = 4 'Définit la derniere ligne a afficher
Do While Not IsEmpty(Range("A" & no_ligneEND))
no_ligneEND = no_ligneEND + 1
Loop
'MsgBox (no_ligne)
'Boucle qui permet de lire les données de la feuille BDD
If no_ligne = 2 Then
Tx_NOM.Text = ""
Tx_NOM.Text = ""
CB_MOIS.Text = ""
Tx_TRA.Text = ""
Tx_DEVIS = ""
CB_OPE.Text = ""
Tx_ACO.Text = ""
CB_ACO.Text = ""
Tx_HV.Text = ""
Tx_POSE.Text = ""
Tx_ETA.Text = ""
FRNS1.Text = ""
LIV1.Text = ""
LCR1.Text = ""
DATE1 = ""
FRNS2.Text = ""
LIV2.Text = ""
CB_L1.Text = ""
LCR2.Text = ""
DATE2 = ""
FRNS3.Text = ""
LIV3.Text = ""
LCR3.Text = ""
DATE3 = ""
FRNS4.Text = ""
LIV4.Text = ""
LCR4.Text = ""
DATE4 = ""
FRNS5.Text = ""
LIV5.Text = ""
LCR5.Text = ""
DATE5 = ""
Tx_RENO = ""
Tx_NEUF = ""
Tx_REHA = ""
Tx_OF1V = ""
Tx_OF2V = ""
Tx_PF1V = ""
Tx_PF2V = ""
Tx_BC = ""
Tx_PE = ""
Tx_VR = ""
Tx_VB = ""
Tx_PERS = ""
Tx_PDG = ""
Tx_PORT = ""
Tx_VER = ""
Tx_AUTRES.Text = ""
Tx_HR.Text = ""
Tx_MO.Text = ""
Tx_Rent.Text = ""
Tx_Marge.Text = ""
CB_L2.Text = ""
CB_L3.Text = ""
CB_L4.Text = ""
CB_L5.Text = ""
Else
Tx_NOM.Text = Cells(no_ligne, 2)
CB_MOIS.Text = Cells(no_ligne, 3)
Tx_TRA.Text = Cells(no_ligne, 4)
Tx_DEVIS = Cells(no_ligne, 5)
CB_OPE.Text = Cells(no_ligne, 6)
Tx_ACO.Text = Cells(no_ligne, 7)
CB_ACO.Text = Cells(no_ligne, 8)
Tx_HV.Text = Cells(no_ligne, 10)
Tx_POSE.Text = Cells(no_ligne, 11)
Tx_ETA.Text = Cells(no_ligne, 33)
FRNS1.Text = Cells(no_ligne, 12)
LIV1.Text = Cells(no_ligne, 13)
LCR1.Text = Cells(no_ligne, 14)
DATE1 = Cells(no_ligne, 15)
CB_L1.Text = Cells(no_ligne, 59)
FRNS2.Text = Cells(no_ligne, 16)
LIV2.Text = Cells(no_ligne, 17)
LCR2.Text = Cells(no_ligne, 18)
DATE2 = Cells(no_ligne, 19)
FRNS3.Text = Cells(no_ligne, 20)
LIV3.Text = Cells(no_ligne, 21)
LCR3.Text = Cells(no_ligne, 22)
DATE3 = Cells(no_ligne, 23)
FRNS4.Text = Cells(no_ligne, 24)
LIV4.Text = Cells(no_ligne, 25)
LCR4.Text = Cells(no_ligne, 26)
DATE4 = Cells(no_ligne, 27)
FRNS5.Text = Cells(no_ligne, 28)
LIV5.Text = Cells(no_ligne, 29)
LCR5.Text = Cells(no_ligne, 30)
DATE5 = Cells(no_ligne, 31)
Tx_RENO = Cells(no_ligne, 35)
Tx_NEUF = Cells(no_ligne, 36)
Tx_REHA = Cells(no_ligne, 37)
Tx_OF1V = Cells(no_ligne, 38)
Tx_OF2V = Cells(no_ligne, 39)
Tx_PF1V = Cells(no_ligne, 40)
Tx_PF2V = Cells(no_ligne, 41)
Tx_BC = Cells(no_ligne, 42)
Tx_PE = Cells(no_ligne, 43)
Tx_VR = Cells(no_ligne, 44)
Tx_VB = Cells(no_ligne, 45)
Tx_PERS = Cells(no_ligne, 46)
Tx_PDG = Cells(no_ligne, 47)
Tx_PORT = Cells(no_ligne, 48)
Tx_VER = Cells(no_ligne, 49)
Tx_AUTRES.Text = Cells(no_ligne, 50)
Tx_HR.Text = Cells(no_ligne, 51)
Tx_MO.Text = Cells(no_ligne, 54)
Tx_Rent.Text = Cells(no_ligne, 56)
Tx_Marge.Text = Cells(no_ligne, 57)
CB_L2.Text = Cells(no_ligne, 60)
CB_L3.Text = Cells(no_ligne, 61)
CB_L4.Text = Cells(no_ligne, 62)
CB_L5.Text = Cells(no_ligne, 63)
End If
'Format de l'affichage des données
Tx_DEVIS.Value = Format(Tx_DEVIS.Value, "# #00.00" & " €")
Tx_ACO.Value = Format(Tx_ACO.Value, "# #00.00" & " €")
LCR1.Value = Format(LCR1.Value, "0.00" & " €")
LCR2.Value = Format(LCR2.Value, "0.00" & " €")
LCR3.Value = Format(LCR3.Value, "0.00" & " €")
LCR4.Value = Format(LCR4.Value, "0.00" & " €")
LCR5.Value = Format(LCR5.Value, "0.00" & " €")
'Tx_MO.Value = Format(Tx_MO, "0.00" & " €")
Tx_Rent.Value = Format(Tx_Rent.Value, "# #0.00")
Tx_Marge.Value = Format(Tx_Marge.Value, "# #00.00" & " €")
Tx_MO.Value = Format(Tx_MO.Value, "# # 000" & " €")
End SubBonne fêtes