cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 2018
-
20 mai 2008 à 13:19
cs_MPi
Messages postés3877Date d'inscriptionmardi 19 mars 2002StatutMembreDernière intervention17 août 2018
-
21 mai 2008 à 01:55
Bonjour à tous,
'[Code UserForm1]
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
Sheets("feuil1").Select
ListBox1.RowSource = "A2:C" & (Range("C2").End(xlDown).Row) + 1
Application.ScreenUpdating = True
End Sub
Private Sub ListBox1_Click()
Dim strUproc As String
Dim i As Integer
If IsEmpty(ListBox1.Column(0)) Then
For i = ListBox1.ListIndex - 1 To 0 Step -1
If Not IsEmpty(ListBox1.List(i, 0)) Then
TextBox3.Text = "BSS n° " & ListBox1.List(i, 0) & vbLf
TextBox3.Text = TextBox3.Text & "Session" & vbTab & ListBox1.List(i, 1) & vbLf
Exit For
End If
Next i
Else
TextBox3.Text = "BSS n° " & ListBox1.Column(0) & vbLf
TextBox3.Text = TextBox3.Text & "Session" & vbTab & ListBox1.Column(1) & vbLf
End If
If Not Range("C" & ListBox1.ListIndex + 2).Comment Is Nothing Then
TextBox3.Text = TextBox3.Text & vbCrLf & _
Range("C" & ListBox1.ListIndex + 2).Comment.Text
Else
TextBox3.Text = TextBox3.Text & vbCrLf & _
"Conditions de reprise non rédigées"
End If
End Sub
Private Sub ComboBox1_DropButtonClick()
Dim recherche As Range
Label4.Caption = ""
Set recherche = Columns.Find(what:=Trim(ComboBox1.Text))
If recherche Is Nothing Then
Label4.Caption = ComboBox1.Text & " non trouvé"
Else
ListBox1.Selected(recherche.Row - 2) = True
End If
Set recherche = Nothing
End Sub
Je me sers du ComboBox pour rechercher un mot (ou chiffre) contenu dans une des 3 colonnes de la ListBox.
Si le mot existe, le Selected se positionne sur la bonne ligne de la ListBox, puis me signale l'erreur suivante:
Erreur d'exécution '380':
Impossible de définir la propriété Selected.
Valeur de propriété non valide.
Je me sers du ComboBox pour rechercher un mot (ou chiffre) contenu dans une des 3 colonnes de la ListBox.
Si le mot existe, le Selected se positionne sur la bonne ligne de la ListBox, puis me signale l'erreur suivante:
Erreur d'exécution '380':
Impossible de définir la propriété Selected.
Valeur de propriété non valide.
Si je mets "ListBox1.Selected(recherche.Row) = True" et je recherche "8888", je n'ai pas d'erreur, mais
- la ligne courante de la ListBox est "fffff02" au lieu de "8888 yxyxyx fffff00";
Puis, si click sur le UserForm, la ligne "fffff02" est dé-selectionnée
et la ligne courante de la ListBox devient la 3ème (aaaaa01).
cs_MPi
Messages postés3877Date d'inscriptionmardi 19 mars 2002StatutMembreDernière intervention17 août 201823 21 mai 2008 à 00:02
Essaie en inversant cette condition, juste pour voir.
J'ai remarqué que If Not...Is Nothing fonctionnait bien contrairement à If... Is Nothing dans certains cas...
If Not recherche Is Nothing Then
ListBox1.Selected(recherche.Row - 2) = True Else
Label4.Caption = ComboBox1.Text & " non trouvé"
End If
Et j'opterais quand même pour le Combobox_Click comme le disait Jimy Neutron.
MPi²
Pour ceux qui programment sous Office, n'oubliez pas qu'il existe un forum dédié à ces applications VBA....... ICI
If ComboBox1.Value <> "" Then
Set recherche = Columns.Find(what:=Trim(ComboBox1.Value))
If recherche Is Nothing Then
Label4.Caption = ComboBox1.Value & " non trouvé"
Else
'ListBox1.ListIndex = recherche.Row - 1
ListBox1.Selected(recherche.Row - 1) = True
If Not IsInList(UCase(ComboBox1.Value), ComboBox1) Then
ComboBox1.AddItem UCase(ComboBox1.Value)
End If
End If
End If
ListBox1.SetFocus
Par contre, la selection issue du combobox positionne la ligne courante sur la dernière ligne de la ListBox1.
Je n'arrive pas à trouver les propriétes pour positionner le résultat de la recherche en haut de la ListBox1.