Bonjour à tous, merci pour vos réponse
@M12, pourquoi mettre un "%" après le "i" ?
pour être plus claire je souhaite une combobox (liste) dans les cellules AA4:AA171 qui récupère les données ligne par ligne de AD4:AO4. de la manières validation des donnèes (liste).
Donc par exemple pour une combobox dans AA4 j'ai la liste des données de la même ligne AD4:AO4
merci de votre aide
Re,
C'est le cas,
pour info le "%" équivaut à l'expression "As Integer"
As-tu au moins testé que chaque ligne dans ta liste déroulante te donne les indications des colonnes correspondantes à la SEULE ligne
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ComboBox1
If Intersect(ActiveCell, [AA4:AA171]) Is Nothing Then .Visible = False: Exit Sub
.Top = ActiveCell.Top
.Left = ActiveCell.Left
.Height = ActiveCell.Height
.Width = ActiveCell.Width
.Visible = True
.Activate
End With
End Sub
Private Sub ComboBox1_GotFocus()
Dim c As Range
With ComboBox1
.Clear 'RAZ
.AddItem "<vide>"
For Each c In ActiveCell(1, 4).Resize(, 12)
If c <> "" Then .AddItem c
Next
Application.ScreenUpdating = True 'mise à jour de l'écran
.DropDown 'déroule la liste
End With
End Sub
Private Sub ComboBox1_Change()
With ComboBox1
If .ListIndex > -1 Then ActiveCell = IIf(.ListIndex = 0, "", .Text): ActiveCell(1, 0).Select
End With
End Sub
Bonjour beloquinto, M12, sousou,
Voyez le fichier joint et ces macros pour la ComboBox :
A+VB:Private Sub Worksheet_SelectionChange(ByVal Target As Range) With ComboBox1 If Intersect(ActiveCell, [AA4:AA171]) Is Nothing Then .Visible = False: Exit Sub .Top = ActiveCell.Top .Left = ActiveCell.Left .Height = ActiveCell.Height .Width = ActiveCell.Width .Clear 'RAZ .Visible = True .Activate End With End Sub Private Sub ComboBox1_GotFocus() Dim c As Range With ComboBox1 .AddItem "<vide>" For Each c In ActiveCell(1, 4).Resize(, 12) If c <> "" Then .AddItem c Next Application.ScreenUpdating = True 'mise à jour de l'écran .DropDown 'déroule la liste End With End Sub Private Sub ComboBox1_Change() With ComboBox1 If .ListIndex > -1 Then ActiveCell = IIf(.ListIndex = 0, "", .Text): ActiveCell(1, 0).Select End With End Sub
J'avais mis .Clear dans la 1ère macro.
Je viens de corriger en mettant cette instruction dans la 2ème macro, c'est plus sûr.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ComboBox1
If Intersect(ActiveCell, [AA4:AA171]) Is Nothing Then .Visible = False: Exit Sub
.Top = ActiveCell.Top
.Left = ActiveCell.Left
.Height = ActiveCell.Height
.Width = ActiveCell.Width
.Visible = True
Application.OnTime 1, Me.CodeName & ".Activation" 'activation différée
End With
End Sub
Sub Activation()
ComboBox1.Activate
End Sub
Private Sub ComboBox1_GotFocus()
Static flag As Boolean 'mémorise la variable
If flag Then Exit Sub
Dim c As Range
With ComboBox1
.Clear 'RAZ
.AddItem "<vide>"
For Each c In ActiveCell(1, 4).Resize(, 12)
If c <> "" Then .AddItem c
Next
flag = True
ActiveCell.Activate 'désactive ComboBox1
.DropDown 'déroule la liste
.Activate 'réactive ComboBox1
flag = False
End With
End Sub
Private Sub ComboBox1_Change()
With ComboBox1
If .ListIndex > -1 Then ActiveCell = IIf(.ListIndex = 0, "", .Text): ActiveCell(1, 0).Select
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range
With ComboBox1
If Intersect(ActiveCell, [AA4:AA171]) Is Nothing Then .Visible = False: Exit Sub
.Clear 'RAZ
.AddItem "<vide>"
For Each c In ActiveCell(1, 4).Resize(, 12)
If c <> "" Then .AddItem c
Next
.Top = ActiveCell.Top
.Left = ActiveCell.Left
.Height = ActiveCell.Height
.Width = ActiveCell.Width
.Visible = True
Application.ScreenUpdating = True 'mise à jour de l'écran
.Activate
End With
End Sub
Private Sub ComboBox1_GotFocus()
ComboBox1.DropDown 'déroule la liste
End Sub
Private Sub ComboBox1_Change()
With ComboBox1
If .ListIndex > -1 Then ActiveCell = IIf(.ListIndex = 0, "", .Text): ActiveCell(1, 0).Select
End With
End Sub
Private Sub Workbook_Open()
Dim c As Range
With Sheets("ARM").ComboBox1
If Not .Visible Then Exit Sub
.AddItem "<vide>"
For Each c In .TopLeftCell.Offset(, 3).Resize(, 12)
If c <> "" Then .AddItem c
Next
End With
End Sub
Une solution peut-être plus simple avec ce fichier (3) :
Mais il faut en plus ce code dans ThisWorkbook pour créer la liste si la ComboBox est affichée :VB:Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim c As Range With ComboBox1 If Intersect(ActiveCell, [AA4:AA171]) Is Nothing Then .Visible = False: Exit Sub .Clear 'RAZ .AddItem "<vide>" For Each c In ActiveCell(1, 4).Resize(, 12) If c <> "" Then .AddItem c Next .Top = ActiveCell.Top .Left = ActiveCell.Left .Height = ActiveCell.Height .Width = ActiveCell.Width .Visible = True Application.ScreenUpdating = True 'mise à jour de l'écran .Activate End With End Sub Private Sub ComboBox1_GotFocus() ComboBox1.DropDown 'déroule la liste End Sub Private Sub ComboBox1_Change() With ComboBox1 If .ListIndex > -1 Then ActiveCell = IIf(.ListIndex = 0, "", .Text): ActiveCell(1, 0).Select End With End Sub
VB:Private Sub Workbook_Open() Dim c As Range With Sheets("ARM").ComboBox1 If Not .Visible Then Exit Sub .AddItem "<vide>" For Each c In .TopLeftCell.Offset(, 3).Resize(, 12) If c <> "" Then .AddItem c Next End With End Sub
De quelles cellules parlez-vous ? S'il s'agit des cellules qui constituent la liste c'est impossible.ajouter aussi les couleurs des cellules correspondante dans la combobox ?