Plusieurs listes déroulantes sur même feuille qui se mélangent
Résolu
noceb
Messages postés
14
Date d'inscription
Statut
Membre
Dernière intervention
-
noceb Messages postés 14 Date d'inscription Statut Membre Dernière intervention -
noceb Messages postés 14 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je souhaite avoir plusieurs listes déroulantes à choix multiples sur la même feuille excel.
J'en ai pour le moment créer 3.
Les listes s'affichent bien lorsque je double-clic sur A6 ou
B10 ou C20 mais ne correspondent pas à la liste souhaitée...
Pouvez-vous me donner un coup de pouce car cela fait un bon petit moment déjà que je tourne autour ?
UserForm1
Private Sub CommandButton1_Click()
Dim i As Byte
Dim ValeurARetourner As String
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
ValeurARetourner = ValeurARetourner & ListBox1.List(i) & " & "
End If
Next i
If ValeurARetourner = "" Then
MsgBox "Sélection obligatoire ou fermez avec la croix"
Exit Sub
End If
ActiveCell = Left(ValeurARetourner, Len(ValeurARetourner) - 3)
ActiveCell.Offset(0, 0).Activate
UserForm1.Hide
Unload UserForm1
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer, Derlig As Integer
ListBox1.Clear
With Sheets("ListesMultiples")
Derlig = .Cells(65536, 1).End(xlUp).Row
For i = 1 To Derlig
ListBox1.AddItem .Cells(i, 1).Value
Next i
End With
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
ListBox1.Selected(i) = False
End If
Next i
End Sub
UserForm2
Private Sub CommandButton2_Click()
Dim i As Byte
Dim ValeurARetourner As String
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) = True Then
ValeurARetourner = ValeurARetourner & ListBox2.List(i) & " & "
End If
Next i
If ValeurARetourner = "" Then
MsgBox "Sélection obligatoire ou fermez avec la croix"
Exit Sub
End If
ActiveCell = Left(ValeurARetourner, Len(ValeurARetourner) - 3)
ActiveCell.Offset(0, 0).Activate
UserForm2.Hide
Unload UserForm2
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer, Derlig As Integer
ListBox2.Clear
With Sheets("ListesMultiples")
Derlig = .Cells(65536, 2).End(xlUp).Row
For i = 1 To Derlig
ListBox2.AddItem .Cells(i, 2).Value
Next i
End With
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) = True Then
ListBox2.Selected(i) = False
End If
Next i
End Sub
UserForm3
Private Sub CommandButton3_Click()
Dim i As Byte
Dim ValeurARetourner As String
For i = 0 To ListBox3.ListCount - 1
If ListBox3.Selected(i) = True Then
ValeurARetourner = ValeurARetourner & ListBox3.List(i) & " & "
End If
Next i
If ValeurARetourner = "" Then
MsgBox "Sélection obligatoire ou fermez avec la croix"
Exit Sub
End If
ActiveCell = Left(ValeurARetourner, Len(ValeurARetourner) - 3)
ActiveCell.Offset(3, 20).Activate
UserForm3.Hide
Unload UserForm3
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer, Derlig As Integer
ListBox3.Clear
With Sheets("ListesMultiples")
Derlig = .Cells(65536, 3).End(xlUp).Row
For i = 1 To Derlig
ListBox3.AddItem .Cells(i, 3).Value
Next i
End With
For i = 0 To ListBox3.ListCount - 1
If ListBox3.Selected(i) = True Then
ListBox3.Selected(i) = False
End If
Next i
End Sub
Sur Feuille "ListesMultiples"
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A6,B10,C20")) Is Nothing Then
Exit Sub
ElseIf Intersect(Target, Range("A6")) Is Nothing Then
Target.Value = ""
Load UserForm2
UserForm2.Show
ElseIf Intersect(Target, Range("B10")) Is Nothing Then
Target.Value = ""
Load UserForm1
UserForm1.Show
ElseIf Intersect(Target, Range("C20")) Is Nothing Then
Target.Value = ""
Load UserForm3
UserForm3.Show
End If
End Sub
Merci beaucoup !
Je souhaite avoir plusieurs listes déroulantes à choix multiples sur la même feuille excel.
J'en ai pour le moment créer 3.
Les listes s'affichent bien lorsque je double-clic sur A6 ou
B10 ou C20 mais ne correspondent pas à la liste souhaitée...
Pouvez-vous me donner un coup de pouce car cela fait un bon petit moment déjà que je tourne autour ?
UserForm1
Private Sub CommandButton1_Click()
Dim i As Byte
Dim ValeurARetourner As String
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
ValeurARetourner = ValeurARetourner & ListBox1.List(i) & " & "
End If
Next i
If ValeurARetourner = "" Then
MsgBox "Sélection obligatoire ou fermez avec la croix"
Exit Sub
End If
ActiveCell = Left(ValeurARetourner, Len(ValeurARetourner) - 3)
ActiveCell.Offset(0, 0).Activate
UserForm1.Hide
Unload UserForm1
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer, Derlig As Integer
ListBox1.Clear
With Sheets("ListesMultiples")
Derlig = .Cells(65536, 1).End(xlUp).Row
For i = 1 To Derlig
ListBox1.AddItem .Cells(i, 1).Value
Next i
End With
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
ListBox1.Selected(i) = False
End If
Next i
End Sub
UserForm2
Private Sub CommandButton2_Click()
Dim i As Byte
Dim ValeurARetourner As String
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) = True Then
ValeurARetourner = ValeurARetourner & ListBox2.List(i) & " & "
End If
Next i
If ValeurARetourner = "" Then
MsgBox "Sélection obligatoire ou fermez avec la croix"
Exit Sub
End If
ActiveCell = Left(ValeurARetourner, Len(ValeurARetourner) - 3)
ActiveCell.Offset(0, 0).Activate
UserForm2.Hide
Unload UserForm2
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer, Derlig As Integer
ListBox2.Clear
With Sheets("ListesMultiples")
Derlig = .Cells(65536, 2).End(xlUp).Row
For i = 1 To Derlig
ListBox2.AddItem .Cells(i, 2).Value
Next i
End With
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) = True Then
ListBox2.Selected(i) = False
End If
Next i
End Sub
UserForm3
Private Sub CommandButton3_Click()
Dim i As Byte
Dim ValeurARetourner As String
For i = 0 To ListBox3.ListCount - 1
If ListBox3.Selected(i) = True Then
ValeurARetourner = ValeurARetourner & ListBox3.List(i) & " & "
End If
Next i
If ValeurARetourner = "" Then
MsgBox "Sélection obligatoire ou fermez avec la croix"
Exit Sub
End If
ActiveCell = Left(ValeurARetourner, Len(ValeurARetourner) - 3)
ActiveCell.Offset(3, 20).Activate
UserForm3.Hide
Unload UserForm3
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer, Derlig As Integer
ListBox3.Clear
With Sheets("ListesMultiples")
Derlig = .Cells(65536, 3).End(xlUp).Row
For i = 1 To Derlig
ListBox3.AddItem .Cells(i, 3).Value
Next i
End With
For i = 0 To ListBox3.ListCount - 1
If ListBox3.Selected(i) = True Then
ListBox3.Selected(i) = False
End If
Next i
End Sub
Sur Feuille "ListesMultiples"
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A6,B10,C20")) Is Nothing Then
Exit Sub
ElseIf Intersect(Target, Range("A6")) Is Nothing Then
Target.Value = ""
Load UserForm2
UserForm2.Show
ElseIf Intersect(Target, Range("B10")) Is Nothing Then
Target.Value = ""
Load UserForm1
UserForm1.Show
ElseIf Intersect(Target, Range("C20")) Is Nothing Then
Target.Value = ""
Load UserForm3
UserForm3.Show
End If
End Sub
Merci beaucoup !
A voir également:
- Plusieurs listes déroulantes sur même feuille qui se mélangent
- Comment faire une liste déroulante sur excel - Guide
- Listes déroulantes en cascade excel - Guide
- Bruler feuille de laurier - Guide
- Feuille de pointage excel - Télécharger - Tableur
- Comment supprimer une feuille sur word - Guide
5 réponses
Bonjour,
Voici le lien créé : https://www.cjoint.com/?3IgtViVOnCL
Il s'agit juste de récupérer en A6,B10,C20,...etc, le résultat des choix multiples accompagnés des &.
Merci.
Voici le lien créé : https://www.cjoint.com/?3IgtViVOnCL
Il s'agit juste de récupérer en A6,B10,C20,...etc, le résultat des choix multiples accompagnés des &.
Merci.
Bonjour,
Si tu pouvais nous mettre un exemple de structure des données, sans éléments personnels, se serait plus facile de t'aider.
Pour communiquer ton classeur tu le télécharges sur https://www.cjoint.com/ et tu mets ici le lien obtenu.
Si tu pouvais nous mettre un exemple de structure des données, sans éléments personnels, se serait plus facile de t'aider.
Pour communiquer ton classeur tu le télécharges sur https://www.cjoint.com/ et tu mets ici le lien obtenu.
Bonjour,
Pour obtenir ton fonctionnement, il faut utiliser "not" et remettre le bon ordre :
Un exemple en tout regroupant sur un seul formulaire :
https://www.cjoint.com/?CIhaVosqlzB
Toujours zen
La perfection est atteinte, non pas lorsqu'il n'y a plus rien à ajouter, mais lorsqu'il n'y a plus rien à retirer. Antoine de Saint-Exupéry
Pour obtenir ton fonctionnement, il faut utiliser "not" et remettre le bon ordre :
ElseIf Not Intersect(Target, Range("A6")) Is Nothing Then
Target.Value = ""
Load UserForm1
UserForm1.Show
ElseIf Not Intersect(Target, Range("B10")) Is Nothing Then
Target.Value = ""
Load UserForm2
UserForm2.Show
ElseIf Not Intersect(Target, Range("C20")) Is Nothing Then
Un exemple en tout regroupant sur un seul formulaire :
https://www.cjoint.com/?CIhaVosqlzB
Toujours zen
La perfection est atteinte, non pas lorsqu'il n'y a plus rien à ajouter, mais lorsqu'il n'y a plus rien à retirer. Antoine de Saint-Exupéry
Bonjour
Oui tu peux mettre aussi un select case
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A6,B10,C20")) Is Nothing Then
Exit Sub
End If
Target.Value = ""
Select Case Target.Address
Case "$A$6"
UserForm1.Show
Case "$B$10"
UserForm2.Show
Case "$C$20"
UserForm3.Show
End Select
End Sub
et pour ta liste
ListBox1.Clear
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
ListBox1.AddItem Range("A" & i).Value
Next i
A+
Maurice
Oui tu peux mettre aussi un select case
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A6,B10,C20")) Is Nothing Then
Exit Sub
End If
Target.Value = ""
Select Case Target.Address
Case "$A$6"
UserForm1.Show
Case "$B$10"
UserForm2.Show
Case "$C$20"
UserForm3.Show
End Select
End Sub
et pour ta liste
ListBox1.Clear
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
ListBox1.AddItem Range("A" & i).Value
Next i
A+
Maurice
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question