VBA alimentation d'une combobox
Résolu
trinit@
Messages postés
119
Date d'inscription
Statut
Membre
Dernière intervention
-
trinit@ Messages postés 119 Date d'inscription Statut Membre Dernière intervention -
trinit@ Messages postés 119 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je reviens vers la communauté pour un soucis d'alimentation d'une combobox multicolonnes. J'ai testé plusieurs scripts, mais impossible d'afficher ce que je souhaite, la combobox reste désespérément vide. Je vous joins le fichier.
http://ww38.toofiles.com/fr/oip/documents/xlsm/tableurfinal.html
(Attention, le code de l'UserForm2 est dégeu, c'est là que je travaille ;) )
Sur la page "Calcul des produits", j'ai créé un bouton ajouter un produit. Je voudrais que le combobox de l'UserForm soit alimenté par le tableau "Produits - Ne pas supprimer", donc avoir 5 colonnes avec la possibilité de sélectionner une ligne dans la liste déroulante qui s'affiche.
La ligne sélectionnée, avec un autre clique sur le bouton OK, viendrais s'ajouter en dessous du tableau des produits déjà inscrit dans la feuille "Calcul des produits". Mais seul le nom du produit viendrais s'afficher dans ce dernier tableau.
Ca va faire maintenant 5 jours que j'essaye des morceaux de codes, mais sans résultats. L'erreur viens donc de moi :/ mais un coup de main serait le bienvenue...
Je reviens vers la communauté pour un soucis d'alimentation d'une combobox multicolonnes. J'ai testé plusieurs scripts, mais impossible d'afficher ce que je souhaite, la combobox reste désespérément vide. Je vous joins le fichier.
http://ww38.toofiles.com/fr/oip/documents/xlsm/tableurfinal.html
(Attention, le code de l'UserForm2 est dégeu, c'est là que je travaille ;) )
Sur la page "Calcul des produits", j'ai créé un bouton ajouter un produit. Je voudrais que le combobox de l'UserForm soit alimenté par le tableau "Produits - Ne pas supprimer", donc avoir 5 colonnes avec la possibilité de sélectionner une ligne dans la liste déroulante qui s'affiche.
La ligne sélectionnée, avec un autre clique sur le bouton OK, viendrais s'ajouter en dessous du tableau des produits déjà inscrit dans la feuille "Calcul des produits". Mais seul le nom du produit viendrais s'afficher dans ce dernier tableau.
Ca va faire maintenant 5 jours que j'essaye des morceaux de codes, mais sans résultats. L'erreur viens donc de moi :/ mais un coup de main serait le bienvenue...
A voir également:
- VBA alimentation d'une combobox
- Connaitre son alimentation pc ✓ - Forum Alimentation PC
- Comment connaitre la puissance de mon alim ? - Forum Matériel & Système
- L'indice n'appartient pas à la sélection vba - Forum VB / VBA
- Incompatibilité de type vba ✓ - Forum Programmation
- Calcul alimentation pc - Guide
6 réponses
Bonjour,
Au moins pour commencer a esperer.
Private Sub UserForm_Activate()
Dim Plage, NbLigne
With Worksheets("Produits - Ne pas supprimer").Activate
'Derniere ligne colonne B
NbLigne = WorksheetFunction.CountA(Columns("B:B"))
'Page de cellules
Plage = Range(Cells(2, 1), Cells(NbLigne, 5)).Address
End With
'Nombre de colonne combobox
ComboBox1.ColumnCount = 5
'largeur Colonnes
ComboBox1.ColumnWidths = "50 pt;50 pt;50 pt;50 pt;50 pt"
'Entetes de colonne
ComboBox1.ColumnHeads = True
'Source combobox
ComboBox1.RowSource = Plage
End Sub
Private Sub ComboBox1_Click()
'Affichage ligne choisie
With ComboBox1
.Text = .Column(0, .ListIndex) & " - " & _
Format(.Column(1, .ListIndex), "0.00") & " - " & _
Format(.Column(2, .ListIndex), "0.00") & " - " & _
Format(.Column(3, .ListIndex), "0.00") & " - " & _
Format(.Column(4, .ListIndex), "0.00") & " - "
End With
End Sub
A+
Au moins pour commencer a esperer.
Private Sub UserForm_Activate()
Dim Plage, NbLigne
With Worksheets("Produits - Ne pas supprimer").Activate
'Derniere ligne colonne B
NbLigne = WorksheetFunction.CountA(Columns("B:B"))
'Page de cellules
Plage = Range(Cells(2, 1), Cells(NbLigne, 5)).Address
End With
'Nombre de colonne combobox
ComboBox1.ColumnCount = 5
'largeur Colonnes
ComboBox1.ColumnWidths = "50 pt;50 pt;50 pt;50 pt;50 pt"
'Entetes de colonne
ComboBox1.ColumnHeads = True
'Source combobox
ComboBox1.RowSource = Plage
End Sub
Private Sub ComboBox1_Click()
'Affichage ligne choisie
With ComboBox1
.Text = .Column(0, .ListIndex) & " - " & _
Format(.Column(1, .ListIndex), "0.00") & " - " & _
Format(.Column(2, .ListIndex), "0.00") & " - " & _
Format(.Column(3, .ListIndex), "0.00") & " - " & _
Format(.Column(4, .ListIndex), "0.00") & " - "
End With
End Sub
A+
Merci f894009 ! Pile ce qu'il me fallait ! Ce tableur est mon rapport final de BTS, je desesperait a l'idée de devoir le fausser à cause de ce VBA... merci !
Re,
Mais seul le nom du produit viendrais s'afficher dans ce dernier tableau.
Quel tableau??????
Mais seul le nom du produit viendrais s'afficher dans ce dernier tableau.
Quel tableau??????
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Re
'declaration pour tout l'Userform
Dim Prod_a_ajouter
'Bouton OK
Private Sub CommandButton1_Click()
Dim x As Integer
Dim c As Range, PCVideA
'Selection de l'onglet
Worksheets("Calcul des produits").Select
'Recherche cellule vide colonne A
Set c = IIf(Range("A5") = "", Range("A5"), Range("A4").End(xlDown))
PCVideA = c.Row + 1
'Insertion ligne
Rows(PCVideA & ":" & PCVideA).Insert Shift:=xlDown
'Ecriture Produit
Cells(PCVideA, 1) = Prod_a_ajouter
'Encadrement cellules
Range("A" & PCVideA & ":C" & PCVideA).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
Modife pour recuperer le Nom Produit
Private Sub ComboBox1_Click()
'Affichage ligne choisie
With ComboBox1
.Text = .Column(0, .ListIndex)
'Nom du produit a ajouter
Prod_a_ajouter = .Text
.Text = .Text & " - " & _
Format(.Column(1, .ListIndex), "0.00") & " - " & _
Format(.Column(2, .ListIndex), "0.00") & " - " & _
Format(.Column(3, .ListIndex), "0.00") & " - " & _
Format(.Column(4, .ListIndex), "0.00")
End With
End Sub
Bonne suite
'declaration pour tout l'Userform
Dim Prod_a_ajouter
'Bouton OK
Private Sub CommandButton1_Click()
Dim x As Integer
Dim c As Range, PCVideA
'Selection de l'onglet
Worksheets("Calcul des produits").Select
'Recherche cellule vide colonne A
Set c = IIf(Range("A5") = "", Range("A5"), Range("A4").End(xlDown))
PCVideA = c.Row + 1
'Insertion ligne
Rows(PCVideA & ":" & PCVideA).Insert Shift:=xlDown
'Ecriture Produit
Cells(PCVideA, 1) = Prod_a_ajouter
'Encadrement cellules
Range("A" & PCVideA & ":C" & PCVideA).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
Modife pour recuperer le Nom Produit
Private Sub ComboBox1_Click()
'Affichage ligne choisie
With ComboBox1
.Text = .Column(0, .ListIndex)
'Nom du produit a ajouter
Prod_a_ajouter = .Text
.Text = .Text & " - " & _
Format(.Column(1, .ListIndex), "0.00") & " - " & _
Format(.Column(2, .ListIndex), "0.00") & " - " & _
Format(.Column(3, .ListIndex), "0.00") & " - " & _
Format(.Column(4, .ListIndex), "0.00")
End With
End Sub
Bonne suite
Re,
Remplace par celui-ci
'declaration pour tout l'Userform
Dim Prod_a_ajouter
Private Sub CommandButton1_Click()
Dim PCVideA
'Selection de l'onglet
Worksheets("Calcul des produits").Select
'Recherche cellule vide colonne A
PCVideA = Columns(1).Find("", Range("A4").End(xlUp), , , xlByRows).Row
'Insertion ligne
Rows(PCVideA & ":" & PCVideA).Insert Shift:=xlDown
'Ecriture Produit
Cells(PCVideA, 1) = Prod_a_ajouter
'Encadrement cellules
Range("A" & PCVideA & ":C" & PCVideA).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
Private Sub ComboBox1_Click()
'Affichage ligne choisie
With ComboBox1
.Text = .Column(0, .ListIndex)
'Nom du produit a ajouter
Prod_a_ajouter = .Text
.Text = .Text & " - " & _
Format(.Column(1, .ListIndex), "0.00") & " - " & _
Format(.Column(2, .ListIndex), "0.00") & " - " & _
Format(.Column(3, .ListIndex), "0.00") & " - " & _
Format(.Column(4, .ListIndex), "0.00")
End With
End Sub
Private Sub UserForm_Activate()
Dim Plage, NbLigne
With Worksheets("Produits - Ne pas supprimer").Activate
'Derniere ligne colonne B
NbLigne = WorksheetFunction.CountA(Columns("B:B"))
'Page de cellules
Plage = Range(Cells(2, 1), Cells(NbLigne, 5)).Address
End With
'Nombre de colonne combobox
ComboBox1.ColumnCount = 5
'largeur Colonnes
ComboBox1.ColumnWidths = "50 pt;50 pt;50 pt;50 pt;50 pt"
'Entetes de colonne
ComboBox1.ColumnHeads = True
'Source combobox
ComboBox1.RowSource = Plage
End Sub
J'ai retrouve une formule de recherche en colonne plus simple.
Remplace par celui-ci
'declaration pour tout l'Userform
Dim Prod_a_ajouter
Private Sub CommandButton1_Click()
Dim PCVideA
'Selection de l'onglet
Worksheets("Calcul des produits").Select
'Recherche cellule vide colonne A
PCVideA = Columns(1).Find("", Range("A4").End(xlUp), , , xlByRows).Row
'Insertion ligne
Rows(PCVideA & ":" & PCVideA).Insert Shift:=xlDown
'Ecriture Produit
Cells(PCVideA, 1) = Prod_a_ajouter
'Encadrement cellules
Range("A" & PCVideA & ":C" & PCVideA).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
Private Sub ComboBox1_Click()
'Affichage ligne choisie
With ComboBox1
.Text = .Column(0, .ListIndex)
'Nom du produit a ajouter
Prod_a_ajouter = .Text
.Text = .Text & " - " & _
Format(.Column(1, .ListIndex), "0.00") & " - " & _
Format(.Column(2, .ListIndex), "0.00") & " - " & _
Format(.Column(3, .ListIndex), "0.00") & " - " & _
Format(.Column(4, .ListIndex), "0.00")
End With
End Sub
Private Sub UserForm_Activate()
Dim Plage, NbLigne
With Worksheets("Produits - Ne pas supprimer").Activate
'Derniere ligne colonne B
NbLigne = WorksheetFunction.CountA(Columns("B:B"))
'Page de cellules
Plage = Range(Cells(2, 1), Cells(NbLigne, 5)).Address
End With
'Nombre de colonne combobox
ComboBox1.ColumnCount = 5
'largeur Colonnes
ComboBox1.ColumnWidths = "50 pt;50 pt;50 pt;50 pt;50 pt"
'Entetes de colonne
ComboBox1.ColumnHeads = True
'Source combobox
ComboBox1.RowSource = Plage
End Sub
J'ai retrouve une formule de recherche en colonne plus simple.