Vba userform
Résolu
la9
-
la9 -
la9 -
2 réponses
Bonjour,
Un exemple vaut parfois mieux qu'un long discours
Codes utilisés :
Userform 1 :
bouton "valider" :
initialisation du UserForm1 :
Userform 2 :
Bouton : "enregistrement des modifications" :
Initialisation des données au chargement de l'USF2 :
Un exemple vaut parfois mieux qu'un long discours
Codes utilisés :
Userform 1 :
bouton "valider" :
Private Sub CommandButton1_Click() If ComboBox1.Value = "" Then MsgBox "Veuillez choisir un nom" Exit Sub End If Load UserForm2 UserForm2.Show End Sub
initialisation du UserForm1 :
Private Sub UserForm_Initialize() Dim DerniereLigne As Integer, Ligne As Integer DerniereLigne = Sheets("Feuil1").Range("A65536").End(xlUp).Row For Ligne = 2 To DerniereLigne ComboBox1.AddItem Cells(Ligne, 1).Value Next Ligne End Sub
Userform 2 :
Bouton : "enregistrement des modifications" :
Private Sub CommandButton1_Click() Dim Trouve As Range Dim Valeur_cherchee As String If TextBox1.Value = "" Then MsgBox "Veuillez entrer un nom" Exit Sub End If Valeur_cherchee = TextBox1.Value Set Trouve = Sheets("Feuil1").Columns(1).Cells.Find(what:=Valeur_cherchee) If Trouve Is Nothing Then MsgBox "Pas trouvé" Else Trouve.Offset(0, 1).Value = TextBox2.Value Trouve.Offset(0, 2).Value = TextBox3.Value Trouve.Offset(0, 3).Value = TextBox4.Value Trouve.Offset(0, 4).Value = TextBox5.Value Trouve.Offset(0, 5).Value = TextBox6.Value End If Set Trouve = Nothing End Sub
Initialisation des données au chargement de l'USF2 :
Private Sub UserForm_Initialize() Dim Trouve As Range Dim Valeur_cherchee As String TextBox1.Value = UserForm1.ComboBox1.Value Valeur_cherchee = TextBox1.Value Set Trouve = Sheets("Feuil1").Columns(1).Cells.Find(what:=Valeur_cherchee) If Trouve Is Nothing Then MsgBox "Pas trouvé" Else TextBox2.Value = Trouve.Offset(0, 1).Value TextBox3.Value = Trouve.Offset(0, 2).Value TextBox4.Value = Trouve.Offset(0, 3).Value TextBox5.Value = Trouve.Offset(0, 4).Value TextBox6.Value = Trouve.Offset(0, 5).Value End If Set Trouve = Nothing End Sub