L'indice n'appartient pas à la sélection, VBA Excel

L'indice n'appartient pas à la sélection, VBA Excel - VB/VBA/VBS - Programmation

Marsh Posté le 15-07-2014 à 12:02:03    

Bonjour le forum,
 
J'ai un gros problème qui m’empêche d'avancer depuis plus d'une semaine. En fait, j'ai une listbox que j'alimente avec le code ci-dessous.  
La troisième colonne de cette dernière contient des liens hypertextes [Feuil2.Cells(I, 6).Value], pour les activer j'utilise le code suivant :
 
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
      ActiveWorkbook.FollowHyperlink Address:=Cells(ListBox1.ListIndex + 3, 6).Hyperlinks(1).Address, _
        NewWindow:=True
End Sub
 
1) Premier problème : quand je clique sur une ligne vide dans la listbox, j'ai le message d’erreur (l'indice n'appartient pas à la sélection)  
2) Deuxième problème : quand j’affiche une partie de mon tableau avec la condition [If Sheets("Heures" ).Cells(I, 14).Value = "En cours" Then] il me mélange les indices.
 
Exemple:  
Dans mon tableau j'ai :
Projet 1
Projet 2               >>>>  Avec la condition [Cells(I, 14).Value = "En cours"]  il me reste >>>         Projet 3
Projet 3                                                                                                                          Projet 4
Projet 4                                                                                                                        
 
Quand je clique sur projet 4 il m'ouvre le lien du projet 1.
 
J'espère que c'était claire et merci d'avance pour votre aide.
Vincent  
 
 
 
 
--------------------------------------------------------------------------------------------------- Code alimentation listbox
Private Sub CommandButton17_Click()
Sheets("Heures" ).Select
 
Dim I As Integer
Acceuil.ListBox1.Clear
Acceuil.ListBox1.ColumnCount = 5
 
For I = 1 To Sheets("Heures" ).Range("A65535" ).End(xlUp).Row
 
If Sheets("Heures" ).Cells(I, 14).Value = "En cours" Then
 
    Acceuil.ListBox1.AddItem
    Acceuil.ListBox1.List(Acceuil.ListBox1.ListCount - 1, 0) = Feuil2.Cells(I, 1).Value
    Acceuil.ListBox1.List(Acceuil.ListBox1.ListCount - 1, 1) = Feuil2.Cells(I, 8).Value
    Acceuil.ListBox1.List(Acceuil.ListBox1.ListCount - 1, 2) = Feuil2.Cells(I, 4).Value
    Acceuil.ListBox1.List(Acceuil.ListBox1.ListCount - 1, 3) = Feuil2.Cells(I, 6).Value
    Acceuil.ListBox1.List(Acceuil.ListBox1.ListCount - 1, 4) = Feuil2.Cells(I, 14).Value
     
End If
Next
 
Acceuil.ListBox1.BoundColumn = 100
Acceuil.ListBox1.ColumnWidths = "75;100;75;150;100"
 
End Sub

Reply

Marsh Posté le 15-07-2014 à 12:02:03   

Reply

Marsh Posté le 16-07-2014 à 11:37:15    

Bonjour,
Quelle différence entre "Heures" et feuil2?
Cells(ListBox1.ListIndex + 3......
pourquoi +3 ?
et dans quelle feuille?
Peut-être manque-t-il des détails
Bonne journée

Reply

Marsh Posté le 18-07-2014 à 06:59:12    

Bonjour,
une façon simple de résoudre ton pb:

 

Private Sub CommandButton1_Click()
Sheets("Heures" ).Select
 
Dim I As Integer
ListBox1.Clear
ListBox1.ColumnCount = 6
 
For I = 1 To Sheets("Heures" ).Range("A65535" ).End(xlUp).Row

 

If Sheets("Heures" ).Cells(I, 14).Value = "En cours" Then
 
    ListBox1.AddItem
    ListBox1.List(ListBox1.ListCount - 1, 0) = Feuil2.Cells(I, 1).Value
    ListBox1.List(ListBox1.ListCount - 1, 1) = Feuil2.Cells(I, 8).Value
   ListBox1.List(ListBox1.ListCount - 1, 2) = Feuil2.Cells(I, 4).Value
   ListBox1.List(ListBox1.ListCount - 1, 3) = Feuil2.Cells(I, 6).Value
   ListBox1.List(ListBox1.ListCount - 1, 4) = Feuil2.Cells(I, 14).Value
     ListBox1.List(ListBox1.ListCount - 1, 5) = I
End If
Next
 
ListBox1.BoundColumn = 100
ListBox1.ColumnWidths = "75;100;75;150;100"
 
End Sub

 

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.Hide

 

marow = ListBox1.List(ListBox1.ListIndex, 5)

 

     ActiveWorkbook.FollowHyperlink Address:=Feuil2.Cells(marow, 6).Hyperlinks(1).Address, _
        NewWindow:=True
     
     
End Sub

 

Message cité 1 fois
Message édité par seniorpapou le 18-07-2014 à 07:00:25
Reply

Marsh Posté le 21-07-2014 à 09:24:20    

seniorpapou a écrit :

Bonjour,
une façon simple de résoudre ton pb:
 
Private Sub CommandButton1_Click()
Sheets("Heures" ).Select
 
Dim I As Integer
ListBox1.Clear
ListBox1.ColumnCount = 6
 
For I = 1 To Sheets("Heures" ).Range("A65535" ).End(xlUp).Row
 
If Sheets("Heures" ).Cells(I, 14).Value = "En cours" Then
 
    ListBox1.AddItem
    ListBox1.List(ListBox1.ListCount - 1, 0) = Feuil2.Cells(I, 1).Value
    ListBox1.List(ListBox1.ListCount - 1, 1) = Feuil2.Cells(I, 8).Value
   ListBox1.List(ListBox1.ListCount - 1, 2) = Feuil2.Cells(I, 4).Value
   ListBox1.List(ListBox1.ListCount - 1, 3) = Feuil2.Cells(I, 6).Value
   ListBox1.List(ListBox1.ListCount - 1, 4) = Feuil2.Cells(I, 14).Value
     ListBox1.List(ListBox1.ListCount - 1, 5) = I
End If
Next
 
ListBox1.BoundColumn = 100
ListBox1.ColumnWidths = "75;100;75;150;100"
 
End Sub
 
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.Hide
 
marow = ListBox1.List(ListBox1.ListIndex, 5)
 
      ActiveWorkbook.FollowHyperlink Address:=Feuil2.Cells(marow, 6).Hyperlinks(1).Address, _
        NewWindow:=True
     
     
End Sub
 


 
Bonjour Seniorpapou,
 
Merci beaucoup pour ton aide et désolé pour ma réponse un peu tardive, ça marche super bien c'est nickel.
 
Cordialement

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed