J'ai besoin de changer la valeur d'une cellule (la cellule active dans mon cas) par la ou les sélections faites dans la ListBox, mais je n'y arrives pas j'ai sans cesse l'erreur "Could not get the selected property. invalid argument" quand j'active la sélection multiple
J'ai 2 boutons me permettant d'alterner entre la sélection simple et la multiple, une ListBox où sont placés les différentes variables et un dernier bouton OK pour valider la sélection et l'appliquer à la cellule active.
Avez vous une solution pour que la sélection multiple fonctionne et change la valeur de la cellule avec les différentes variables ?
VB:
Option Explicit
Dim i As Integer
Private Sub CommandButton1_Click()
For i = 0 To 10
If ListBox1.Selected(i) Then
ActiveCell.Value = ListBox1.List(i) & Chr(2)
End If
Next
UserForm1.Hide
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub OptionButton1_Click()
ListBox1.MultiSelect = fmMultiSelectSingle
End Sub
Private Sub OptionButton2_Click()
ListBox1.MultiSelect = fmMultiSelectMulti
End Sub
Private Sub UserForm_initialize()
ListBox1.AddItem "Test 1"
ListBox1.AddItem "Test 2"
ListBox1.AddItem "Test 3"
ListBox1.AddItem "Test 4"
ListBox1.AddItem "Test 5"
OptionButton1.Value = True
CommandButton1.AutoSize = True
End Sub
Private Sub CommandButton1_Click()
Dim sep$, i&, x$
sep = " - " 'ou vbLf
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then x = x & sep & .List(i)
Next
ActiveCell = Mid(x, Len(sep) + 1)
End With
UserForm1.Hide
End Sub
Private Sub CommandButton1_Click()
Dim sep$, i&, x$
sep = " - " 'ou vbLf
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then x = x & sep & .List(i)
Next
ActiveCell = Mid(x, Len(sep) + 1)
End With
UserForm1.Hide
End Sub
Normal, vous chargez 5 items (dans userform_initialize) et vous en parcourrez 11 (boucle for)
Voyez si ceci fonctionne sinon, donnez nous un classeur exemple.
Et vous êtes sûr du chr(2) ne serait-ce pas chr(12)?
VB:
Private Sub CommandButton1_Click()
Dim i As Integer
Dim Res As String
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then Res = Res & ListBox1.List(i) & Chr(2)
Next
ActiveCell.Value = Res
End Sub