Userform excel
toutinne
Messages postés
1
Date d'inscription
Statut
Membre
Dernière intervention
-
Frenchie83 Messages postés 2240 Date d'inscription Statut Membre Dernière intervention -
Frenchie83 Messages postés 2240 Date d'inscription Statut Membre Dernière intervention -
bonjour je suis débutante en vba pour excel, jai crée pour ma cie un userform d'entree des rejets avec détails pour fin de statistiques (et facilités l'entrée des utilisateurs) mon userform contient un combobox qui va chercher par no.de rejet ceux existant et les ramene dans le userform, mais la j'ai besoin de rajouter une liste de choix que l'utilisateur sélectionnera et qui s'ajoutera dans l'onglet des données et je n'y parviens pas.
voici mon code
icit
Private Sub ComboBox1_Click()
Dim i As Byte
CommandButton3.Visible = True
CommandButton4.Visible = True
Label27.Caption = "mode Modification/Suivis"
With ComboBox1
For i = 1 To 16
Controls("TextBox" & i) = Sheets("feuil2").Cells(.List(.ListIndex, 1), i)
Next i
End With
End Sub
Private Sub ComboBox2_Change()
Dim i As Byte
With ComboBox2
For i = 1 To 16
Controls("TextBox" & i) = Sheets("feuil2").Cells(.List(.ListIndex, 1), i)
Next i
End With
End Sub
Private Sub CommandButton1_Click()
Dim Dl As Long
Dim x As Byte
With Sheets("Feuil2")
.Activate
Dl = .Range("A65536").End(xlUp).Row + 1
For x = 1 To 16
.Cells(Dl, x).Value = Me.Controls("TextBox" & x).Value
Next x
Unload Me
End With
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub CommandButton3_Click()
Dim i As Byte
With ComboBox1
For i = 1 To 16
Sheets("feuil2").Cells(.List(.ListIndex, 1), i) = Controls("TextBox" & i)
Controls("TextBox" & i) = ""
Next i
.ListIndex = -1
End With
CommandButton3.Visible = False
CommandButton4.Visible = False
Label27.Caption = "mode : création"
initialisecombo
End Sub
Private Sub CommandButton4_Click()
Dim i As Byte
With ComboBox1
For i = 1 To 16
Controls("TextBox" & i) = ""
Next i
.ListIndex = -1
End With
CommandButton3.Visible = False
CommandButton4.Visible = False
Label27.Caption = "mode : Ajout nouveau QC"
End Sub
Private Sub UserForm_Initialize()
Label27.Caption = "mode : création"
initialisecombo
TextBox3.Value = Date
TextBox3.Value = Format(TextBox3.Value, "yyyy-mm-dd")
TextBox7.Value = Format(TextBox7.Value, "yyyy-mm-dd")
TextBox15.Value = Format(TextBox15.Value, "yyyy-mm-dd")
TextBox17 = Sheets("feuil2").Range("v1").Value
End Sub
Public Sub initialisecombo()
Dim i As Integer
With ComboBox1
.Clear
.ColumnCount = 2
.ColumnWidths = "50;0"
End With
With Sheets("feuil2")
For i = 2 To .Range("a65536").End(xlUp).Row
ComboBox1.AddItem
ComboBox1.List(ComboBox1.ListCount - 1, 0) = .Cells(i, 1) & " " & .Cells(i, 2)
ComboBox1.List(ComboBox1.ListCount - 1, 1) = i
Next i
End With
End Sub
voici mon code
icit
Private Sub ComboBox1_Click()
Dim i As Byte
CommandButton3.Visible = True
CommandButton4.Visible = True
Label27.Caption = "mode Modification/Suivis"
With ComboBox1
For i = 1 To 16
Controls("TextBox" & i) = Sheets("feuil2").Cells(.List(.ListIndex, 1), i)
Next i
End With
End Sub
Private Sub ComboBox2_Change()
Dim i As Byte
With ComboBox2
For i = 1 To 16
Controls("TextBox" & i) = Sheets("feuil2").Cells(.List(.ListIndex, 1), i)
Next i
End With
End Sub
Private Sub CommandButton1_Click()
Dim Dl As Long
Dim x As Byte
With Sheets("Feuil2")
.Activate
Dl = .Range("A65536").End(xlUp).Row + 1
For x = 1 To 16
.Cells(Dl, x).Value = Me.Controls("TextBox" & x).Value
Next x
Unload Me
End With
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub CommandButton3_Click()
Dim i As Byte
With ComboBox1
For i = 1 To 16
Sheets("feuil2").Cells(.List(.ListIndex, 1), i) = Controls("TextBox" & i)
Controls("TextBox" & i) = ""
Next i
.ListIndex = -1
End With
CommandButton3.Visible = False
CommandButton4.Visible = False
Label27.Caption = "mode : création"
initialisecombo
End Sub
Private Sub CommandButton4_Click()
Dim i As Byte
With ComboBox1
For i = 1 To 16
Controls("TextBox" & i) = ""
Next i
.ListIndex = -1
End With
CommandButton3.Visible = False
CommandButton4.Visible = False
Label27.Caption = "mode : Ajout nouveau QC"
End Sub
Private Sub UserForm_Initialize()
Label27.Caption = "mode : création"
initialisecombo
TextBox3.Value = Date
TextBox3.Value = Format(TextBox3.Value, "yyyy-mm-dd")
TextBox7.Value = Format(TextBox7.Value, "yyyy-mm-dd")
TextBox15.Value = Format(TextBox15.Value, "yyyy-mm-dd")
TextBox17 = Sheets("feuil2").Range("v1").Value
End Sub
Public Sub initialisecombo()
Dim i As Integer
With ComboBox1
.Clear
.ColumnCount = 2
.ColumnWidths = "50;0"
End With
With Sheets("feuil2")
For i = 2 To .Range("a65536").End(xlUp).Row
ComboBox1.AddItem
ComboBox1.List(ComboBox1.ListCount - 1, 0) = .Cells(i, 1) & " " & .Cells(i, 2)
ComboBox1.List(ComboBox1.ListCount - 1, 1) = i
Next i
End With
End Sub
A voir également:
- Userform excel
- Liste déroulante excel - Guide
- Word et excel gratuit - Guide
- Déplacer colonne excel - Guide
- Si ou excel - Guide
- Excel moyenne - Guide
1 réponse
Bonjour
Afficher toute une page de code, simplement pour demander la création d'une liste de choix, je ne vois pas trop l'intérêt.
Si vous savez programmer en VBA, créer un Formulaire, vous savez sûrement vous servir d'Excel, et créer un liste déroulante.
Le but étant de sélectionner votre liste, lui donner un nom dans la zone de Nom( en haut à gauche, à côté de la zone d'entrée des formules) et valider par Entrée.
Ensuite, dans les propriétés de la boîte de dialogue, inscrire le Nom donnée à cette liste, ou bien, choisir une cellule, et par le même principe, lui affecter une validation de données, sélectionnez Liste et taper =Nom de votre liste.
Si vous ne vous en sortez pas, reformulez votre demande avec des informations claires et précises, et si possible mettez sur cjoint.com votre fichier sans données personnelles, vous verrez, beaucoup de personnes s'intéresseront à votre problème.
bonne journée
cdlt
Afficher toute une page de code, simplement pour demander la création d'une liste de choix, je ne vois pas trop l'intérêt.
Si vous savez programmer en VBA, créer un Formulaire, vous savez sûrement vous servir d'Excel, et créer un liste déroulante.
Le but étant de sélectionner votre liste, lui donner un nom dans la zone de Nom( en haut à gauche, à côté de la zone d'entrée des formules) et valider par Entrée.
Ensuite, dans les propriétés de la boîte de dialogue, inscrire le Nom donnée à cette liste, ou bien, choisir une cellule, et par le même principe, lui affecter une validation de données, sélectionnez Liste et taper =Nom de votre liste.
Si vous ne vous en sortez pas, reformulez votre demande avec des informations claires et précises, et si possible mettez sur cjoint.com votre fichier sans données personnelles, vous verrez, beaucoup de personnes s'intéresseront à votre problème.
bonne journée
cdlt