Formulaire VBA

Bonjour le Forum

Novice sous VBA j'ai tenté de faire un formulaire avec du VBA pour remplir un tableau.

Ca me remonte pleins de messages d'erreur....je voulais faire dans ce formulaire 3 zones de liste déroulantes :

  • ID
  • Référence
  • Désignation

et 3 boutons

  • Modifier
  • Nouveau
  • Quitter
En plus du reste

Et alors après j'aurais aimé un bouton sur une feuille vierge qui me lance le formulaire, plus compliqué à réaliser.

Je joint le code VBA et le fichier en PJ

Si quelqu'un peut venir à mon secours Merci

Option Explicit

Dim Ws As Worksheet

Private Sub Label33_Click()

End Sub

'Pour le formulaire

Private Sub UserForm_Initialize()

Dim J As Long

Dim I As Integer

ComboBox2.ColumnCount = 1

'Pour la liste déroulante Référence

ComboBox2.List() = Array()

Set Ws = Sheets(« Stock »)

'Correspond au nom de votre onglet dans le fichier Excel

With Me.ComboBox1

For J = 2 To Ws.Range(« A » & Rows.Count).End(xlUp).Row

.AddItem Ws.Range(« A » & J)

Next J

End With

For I = 1 To 7

Me.Controls(« TextBox » & I).Visible = True

Next I

End Sub

Pour le bouton Nouveau matériel, saisissez à la suite :

'Pour le bouton Nouveau contact

Private Sub CommandButton1_Click()

Dim L As Integer

If MsgBox(« Confirmez-vous l’insertion de ce nouveau matériel ? », vbYesNo, « Demande de confirmation d’ajout ») = vbYes Then

L = Sheets(« référence »).Range(« a65536?).End(xlUp).Row + 1 ‘Pour placer le nouvel enregistrement à la première ligne de tableau non vide

Range(« A » & L).Value = ComboBox1

Range(« E » & L).Value = ComboBox2

Range(« D » & L).Value = TextBox75

Range(« F » & L).Value = TextBox86

Range(« G » & L).Value = TextBox85

Range(« H » & L).Value = TextBox84

Range(« I » & L).Value = TextBox83

Range(« J » & L).Value = TextBox84

Range(« K » & L).Value = TextBox82

Range(« L » & L).Value = TextBox81

Range(« M » & L).Value = TextBox80

Range(« N » & L).Value = TextBox79

Range(« O » & L).Value = TextBox78

Range(« P » & L).Value = TextBox77

Range(« Q » & L).Value = TextBox76

Range(« C » & L).Value = TextBox26

Range(« R » & L).Value = TextBox13

Range(« S » & L).Value = TextBox14

Range(« T » & L).Value = TextBox15

Range(« U » & L).Value = TextBox16

Range(« V » & L).Value = TextBox18

Range(« W » & L).Value = TextBox19

Range(« X » & L).Value = TextBox20

Range(« Y » & L).Value = TextBox21

Range(« Z » & L).Value = TextBox22

Range(« AA » & L).Value = TextBox23

Range(« AB » & L).Value = TextBox24

'Pour le bouton Modifier

Private Sub CommandButton2_Click()

Dim Ligne As Long

Dim I As Integer

If MsgBox(« Confirmez-vous la modification de ce matériel ? », vbYesNo, « Demande de confirmation de modification ») = vbYes Then

If Me.ComboBox1.ListIndex = -1 Then Exit Sub

Ligne = Me.ComboBox1.ListIndex + 2

Ws.Cells(Ligne, « B ») = ComboBox2

For I = 1 To 7

If Me.Controls(« TextBox » & I).Visible = True Then

Ws.Cells(Ligne, I + 2) = Me.Controls(« TextBox » & I)

End If

Next I

End If

End Sub

Pour le bouton Quitter

Private Sub CommandButton3_Click()

Unload Me

End Sub


oups voici le fichier

Bonjour euclyde31

a tester si cela convient

Rechercher des sujets similaires à "formulaire vba"