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
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