Microsoft 365 formulaire VBA problème

burbi

XLDnaute Nouveau
Bonjour !

Je souhaite mettre en place un formulaire afin de pouvori remplir automatiquement l'onglet "Base de données"
Cependant, les CommandButton que j'ai programmé ne fonctionnent pas...

Quelqu'un pour m'aider ?

Ci dessous le code VBA :

VB:
Sub UserForm_Conf()

 For I = 1 To 7
     Me.Controls("TextBox" & I).Visible = True
 Next I

End Sub

Sub UserForm_Initialize()

Dim J As Long

Dim I As Integer

SetWs = Sheets("Base de données")

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 6
Me.Controls(" TextBox " & I).Visible = True
Next I
End Sub


'Pour le bouton Nouveau contact

Sub CommandButton1_Click()

Dim L As Integer

 If MsgBox("Confirmez-vous l'insertion de ce nouveau deal ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then
     L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement à la première ligne de tableau non vide

     Range("A" & L).Value = TextBox1
     Range("B" & L).Value = TextBox2
     Range("C" & L).Value = TextBox3
     Range("D" & L).Value = TextBox4
     Range("E" & L).Value = TextBox5
     Range("F" & L).Value = TextBox6
     Range("G" & L).Value = TextBox7
     Range("H" & L).Value = TextBox8
     Range("I" & L).Value = TextBox9
     Range("J" & L).Value = TextBox10
     Range("K" & L).Value = TextBox11
     Range("L" & L).Value = TextBox12
     Range("M" & L).Value = TextBox13
     Range("N" & L).Value = TextBox14
     Range("O" & L).Value = TextBox15
     Range("P" & L).Value = TextBox16
     Range("R" & L).Value = TextBox17
     Range("S" & L).Value = TextBox18
     Range("T" & L).Value = TextBox19
     Range("U" & L).Value = TextBox20
     Range("X" & L).Value = TextBox21

    
 End If
 End Sub
 
 'Pour le bouton Modifier

Sub CommandButton2_Click()

Dim Ligne As Long
Dim I As Integer

   If MsgBox("Confirmez-vous la modification de ce Deal ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then
     If Me.ComboBox1.ListIndex = -1 Then Exit Sub

         Ligne = Me.ComboBox1.ListIndex + 2

     For I = 1 To 21
         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
Sub CommandButton3_Click()

Unload Me

End Sub

Sub Ouvir_formualire()
Set Ws = Sheets("Base de données")
UserForm1.Show
End Sub
Sub UserForm_Conf()

For I = 1 To 7
Me.Controls("TextBox" & I).Visible = True
Next I

End Sub

Sub UserForm_Initialize()

Dim J As Long

Dim I As Integer

SetWs = Sheets("Base de données")

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 6
Me.Controls(" TextBox " & I).Visible = True
Next I
End Sub


'Pour le bouton Nouveau contact

Sub CommandButton1_Click()

Dim L As Integer

If MsgBox("Confirmez-vous l'insertion de ce nouveau deal ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then
L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement à la première ligne de tableau non vide

Range("A" & L).Value = TextBox1
Range("B" & L).Value = TextBox2
Range("C" & L).Value = TextBox3
Range("D" & L).Value = TextBox4
Range("E" & L).Value = TextBox5
Range("F" & L).Value = TextBox6
Range("G" & L).Value = TextBox7
Range("H" & L).Value = TextBox8
Range("I" & L).Value = TextBox9
Range("J" & L).Value = TextBox10
Range("K" & L).Value = TextBox11
Range("L" & L).Value = TextBox12
Range("M" & L).Value = TextBox13
Range("N" & L).Value = TextBox14
Range("O" & L).Value = TextBox15
Range("P" & L).Value = TextBox16
Range("R" & L).Value = TextBox17
Range("S" & L).Value = TextBox18
Range("T" & L).Value = TextBox19
Range("U" & L).Value = TextBox20
Range("X" & L).Value = TextBox21


End If
End Sub

'Pour le bouton Modifier

Sub CommandButton2_Click()

Dim Ligne As Long
Dim I As Integer

If MsgBox("Confirmez-vous la modification de ce Deal ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then
If Me.ComboBox1.ListIndex = -1 Then Exit Sub

Ligne = Me.ComboBox1.ListIndex + 2

For I = 1 To 21
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
Sub CommandButton3_Click()

Unload Me

End Sub

Sub Ouvir_formualire()
Set Ws = Sheets("Base de données")
UserForm1.Show
End Sub
[/ICODE]


Ci joi t le fichier excel, MERCI !
 

Pièces jointes

  • FICHIERXLS..xlsm
    152 KB · Affichages: 11

M12

XLDnaute Accro
Bonjour !

Je souhaite mettre en place un formulaire afin de pouvori remplir automatiquement l'onglet "Base de données"
Cependant, les CommandButton que j'ai programmé ne fonctionnent pas...

Quelqu'un pour m'aider ?

Ci dessous le code VBA :

VB:
Sub UserForm_Conf()

 For I = 1 To 7
     Me.Controls("TextBox" & I).Visible = True
 Next I

End Sub

Sub UserForm_Initialize()

Dim J As Long

Dim I As Integer

SetWs = Sheets("Base de données")

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 6
Me.Controls(" TextBox " & I).Visible = True
Next I
End Sub


'Pour le bouton Nouveau contact

Sub CommandButton1_Click()

Dim L As Integer

 If MsgBox("Confirmez-vous l'insertion de ce nouveau deal ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then
     L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement à la première ligne de tableau non vide

     Range("A" & L).Value = TextBox1
     Range("B" & L).Value = TextBox2
     Range("C" & L).Value = TextBox3
     Range("D" & L).Value = TextBox4
     Range("E" & L).Value = TextBox5
     Range("F" & L).Value = TextBox6
     Range("G" & L).Value = TextBox7
     Range("H" & L).Value = TextBox8
     Range("I" & L).Value = TextBox9
     Range("J" & L).Value = TextBox10
     Range("K" & L).Value = TextBox11
     Range("L" & L).Value = TextBox12
     Range("M" & L).Value = TextBox13
     Range("N" & L).Value = TextBox14
     Range("O" & L).Value = TextBox15
     Range("P" & L).Value = TextBox16
     Range("R" & L).Value = TextBox17
     Range("S" & L).Value = TextBox18
     Range("T" & L).Value = TextBox19
     Range("U" & L).Value = TextBox20
     Range("X" & L).Value = TextBox21

  
 End If
 End Sub
 
 'Pour le bouton Modifier

Sub CommandButton2_Click()

Dim Ligne As Long
Dim I As Integer

   If MsgBox("Confirmez-vous la modification de ce Deal ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then
     If Me.ComboBox1.ListIndex = -1 Then Exit Sub

         Ligne = Me.ComboBox1.ListIndex + 2

     For I = 1 To 21
         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
Sub CommandButton3_Click()

Unload Me

End Sub

Sub Ouvir_formualire()
Set Ws = Sheets("Base de données")
UserForm1.Show
End Sub
Sub UserForm_Conf()

For I = 1 To 7
Me.Controls("TextBox" & I).Visible = True
Next I

End Sub

Sub UserForm_Initialize()

Dim J As Long

Dim I As Integer

SetWs = Sheets("Base de données")

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 6
Me.Controls(" TextBox " & I).Visible = True
Next I
End Sub


'Pour le bouton Nouveau contact

Sub CommandButton1_Click()

Dim L As Integer

If MsgBox("Confirmez-vous l'insertion de ce nouveau deal ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then
L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement à la première ligne de tableau non vide

Range("A" & L).Value = TextBox1
Range("B" & L).Value = TextBox2
Range("C" & L).Value = TextBox3
Range("D" & L).Value = TextBox4
Range("E" & L).Value = TextBox5
Range("F" & L).Value = TextBox6
Range("G" & L).Value = TextBox7
Range("H" & L).Value = TextBox8
Range("I" & L).Value = TextBox9
Range("J" & L).Value = TextBox10
Range("K" & L).Value = TextBox11
Range("L" & L).Value = TextBox12
Range("M" & L).Value = TextBox13
Range("N" & L).Value = TextBox14
Range("O" & L).Value = TextBox15
Range("P" & L).Value = TextBox16
Range("R" & L).Value = TextBox17
Range("S" & L).Value = TextBox18
Range("T" & L).Value = TextBox19
Range("U" & L).Value = TextBox20
Range("X" & L).Value = TextBox21


End If
End Sub

'Pour le bouton Modifier

Sub CommandButton2_Click()

Dim Ligne As Long
Dim I As Integer

If MsgBox("Confirmez-vous la modification de ce Deal ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then
If Me.ComboBox1.ListIndex = -1 Then Exit Sub

Ligne = Me.ComboBox1.ListIndex + 2

For I = 1 To 21
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
Sub CommandButton3_Click()

Unload Me

End Sub

Sub Ouvir_formualire()
Set Ws = Sheets("Base de données")
UserForm1.Show
End Sub
[/ICODE]


Ci joi t le fichier excel, MERCI !
Bonjour,
Déjà les macro pour les command de bouton se font dans l'userform
De plus, il faudrait peut-être voir d'où vient le combobox1 dans ce même userform. 'Et je n'ai pas poussé plus loin)

Bref, cela doit être une copie d'un code trouvé je ne sais où et coller pour ne pas fonctionner.
Tout est à supprimer et à faire
 

herve62

XLDnaute Barbatruc
Supporter XLD
Bonsoir
@burbi : Arrête ton "YouTube" , il y a de meilleurs sites pour apprendre le VBA dont celui hélas de notre ami feu Jacques Boisgontier mais son site est resté intact > VBA complet
On ne peut pas mieux , TOUT Y EST !!! simple et facile , juste prendre beaucoup de temps
Sinon j'ai juste remis les pendules à l'heure à savoir , mettre les sub au bon endroit , corriger les erreurs de syntaxe
Là maintenant si tu lances ton USF via ton bouton c'est correct
Maintenant à toi de poursuivre !!
 

Pièces jointes

  • FICHIERXLS.xlsm
    159.6 KB · Affichages: 9
Dernière édition:

Statistiques des forums

Discussions
311 545
Messages
2 080 564
Membres
101 256
dernier inscrit
Ludmi