Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

erreur de proprete non valide

silverjet

XLDnaute Junior
bonjour,

j ai essayer d adapter un code vba pour mon userform de recherche mais il y a un probleme , quand j le lance il me dit erreur de propriete non valide pouvez vous m aider?

voici le code merci.

Option Explicit

Private Sub ComboBox1_Change()
Dim Lig As Long, C As Byte, Item As Variant
Dim D As Object, Cel As Range, Rng As Range

If ComboBox1.ListIndex = -1 Then Exit Sub

C = ComboBox1.ListIndex + 1

If C = 2 Then
ComboBox3.Visible = True
Label3.Visible = True
Label2.Caption = "Date début"
Else
ComboBox3.Visible = False
Label3.Visible = False
Label2.Caption = "Votre choix"
End If

Set D = CreateObject("Scripting.Dictionary")
Set Rng = Sheets("2").Range(Cells(2, C), Cells(Cells(65536, C).End(xlUp).Row, C))
For Each Cel In Rng
If Not D.Exists(Cel.Value) Then D.Add Cel.Value, Cel.Value
Next Cel

If C = 2 Then
ComboBox2.Clear: ComboBox3.Clear
For Each Item In D.items
ComboBox2.AddItem Item
ComboBox3.AddItem Item
Next Item

Else
With ComboBox2
.Clear
For Each Item In D.items
.AddItem Item
Next Item
End With
End If

End Sub

Private Sub ComboBox2_Change()
Dim Cel As Range, Rng As Range, C As Byte

If ComboBox2.ListIndex = -1 Then Exit Sub
C = ComboBox1.ListIndex + 1
ListBox1.Clear
Set Rng = Sheets("2").Range(Cells(2, C), Cells(Cells(65536, C).End(xlUp).Row, C))
For Each Cel In Rng
If Cel = ComboBox2 Then
If C = 1 Then
With ListBox1
.AddItem Cel
.List(.ListCount - 1, 1) = Cel.Offset(0, 1)
.List(.ListCount - 1, 2) = Cel.Offset(0, 2)
.List(.ListCount - 1, 3) = Cel.Offset(0, 3)
.List(.ListCount - 1, 4) = Cel.Offset(0, 4)
.List(.ListCount - 1, 5) = Cel.Offset(0, 5)
.List(.ListCount - 1, 6) = Cel.Offset(0, 6)
.List(.ListCount - 1, 7) = Cel.Offset(0, 7)
.List(.ListCount - 1, 8) = Cel.Offset(0, 8)
.List(.ListCount - 1, 9) = Cel.Offset(0, 9)
.List(.ListCount - 1, 10) = Cel.Offset(0, 10)

End With
End If
If C = 3 Then
With ListBox1
.AddItem Cel.Offset(0, -2)
.List(.ListCount - 1, 1) = Cel.Offset(0, -1)
.List(.ListCount - 1, 2) = Cel
.List(.ListCount - 1, 3) = Cel.Offset(0, 1)
.List(.ListCount - 1, 4) = Cel.Offset(0, 2)
.List(.ListCount - 1, 5) = Cel.Offset(0, 3)
.List(.ListCount - 1, 6) = Cel.Offset(0, 4)
.List(.ListCount - 1, 7) = Cel.Offset(0, 5)
.List(.ListCount - 1, 8) = Cel.Offset(0, 6)
.List(.ListCount - 1, 9) = Cel.Offset(0, 7)
.List(.ListCount - 1, 10) = Cel.Offset(0, 8)
End With
End If
End If
Next Cel

End Sub
Private Sub ComboBox3_Change()
Dim Cel As Range, Rng As Range, C As Byte

If ComboBox3.ListIndex = -1 Then Exit Sub
C = ComboBox1.ListIndex + 1
If ComboBox3.Value < ComboBox2.Value Then Exit Sub
ListBox1.Clear
Set Rng = Sheets("2").Range(Cells(2, C), Cells(Cells(65536, C).End(xlUp).Row, C))
For Each Cel In Rng
If Cel >= CDate(ComboBox2) And Cel <= CDate(ComboBox3) Then
With ListBox1
.AddItem Cel.Offset(0, -1)
.List(.ListCount - 1, 1) = Cel
.List(.ListCount - 1, 2) = Cel.Offset(0, 1)
.List(.ListCount - 1, 3) = Cel.Offset(0, 2)
.List(.ListCount - 1, 4) = Cel.Offset(0, 3)
.List(.ListCount - 1, 5) = Cel.Offset(0, 4)
.List(.ListCount - 1, 6) = Cel.Offset(0, 5)
.List(.ListCount - 1, 7) = Cel.Offset(0, 6)
.List(.ListCount - 1, 8) = Cel.Offset(0, 7)
.List(.ListCount - 1, 9) = Cel.Offset(0, 8)
.List(.ListCount - 1, 10) = Cel.Offset(0, 9)


End With
End If
Next Cel

End Sub

Private Sub ListBox1_Click()
Dim C As Byte

If ListBox1.ListIndex = -1 Then Exit Sub

For C = 0 To 10
Controls("TextBox" & C + 1) = ListBox1.List(ListBox1.ListIndex, C)
Next C

End Sub

Private Sub UserForm_Initialize()

With Sheets("2")
ComboBox1.List = Application.Transpose(.Range("A1:C1").Value)
End With

With ListBox1
.ColumnCount = 25
.ColumnWidths = "50;50;50;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15"
End With

ComboBox3.Visible = False
Label3.Visible = False
TextBox1.Visible = True
TextBox2.Visible = True
TextBox3.Visible = True
TextBox4.Visible = True
TextBox5.Visible = True
TextBox6.Visible = True
TextBox7.Visible = True
TextBox8.Visible = True
TextBox9.Visible = True
Frame3.Visible = False
End Sub
 

jp14

XLDnaute Barbatruc
Re : erreur de proprete non valide

Bonjour

Une première piste dans un textbox on est limité à 10 colonnes, il faut rechercher dans le forum pour pouvoir en afficher plus.
Une listview permet d'en afficher plus.

Cette écriture 15;1 5; posera des problèmes.
Normalement la ligne avec une erreur est surligné.

JP
 

silverjet

XLDnaute Junior
Re : erreur de proprete non valide

merci jp14

je pense que tu as raison une listview et plus appropriée mais comme tu doit t en douter je debute peut tu m aider a adapter le code pour une listeview?

d avance merci .
 

jp14

XLDnaute Barbatruc
Re : erreur de proprete non valide

Bonjour

Avec un fichier qui contient les éléments et des données non confidentielles cela faciliterait l'écriture de la procédure.

Un exemple ci dessous

JP
 

Pièces jointes

  • Listview_aulieu listbox.zip
    28.5 KB · Affichages: 32
  • Listview_aulieu listbox.zip
    28.5 KB · Affichages: 28
  • Listview_aulieu listbox.zip
    28.5 KB · Affichages: 28

silverjet

XLDnaute Junior
Re : erreur de proprete non valide

merci pour le fichier


voila je te joint le mien pour que tu puisse comprendre


et encore merci
 

Pièces jointes

  • Classeur1.xls
    48.5 KB · Affichages: 45
  • Classeur1.xls
    48.5 KB · Affichages: 39
  • Classeur1.xls
    48.5 KB · Affichages: 40

jp14

XLDnaute Barbatruc
Re : erreur de proprete non valide

Bonjour

Ci joint le fichier avec une listview, par rapport à l'exemple j'ai modifié la procédure pour remplir la listview en supprimant les lignes.

J' ai remplacé le lignes de remplissage de la listbox par un call à la procédure pour remplir la listview.

A tester

JP
 

Pièces jointes

  • Classeur1b.zip
    23.6 KB · Affichages: 35
  • Classeur1b.zip
    23.6 KB · Affichages: 40
  • Classeur1b.zip
    23.6 KB · Affichages: 40
Dernière édition:

Discussions similaires

Réponses
4
Affichages
231
Réponses
2
Affichages
171
Réponses
15
Affichages
523
Réponses
17
Affichages
905
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…