1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| Option Explicit
Sub AjouterItem(ByRef oCollection As Collection, ByVal strItem As String)
Dim oObjet As Object
Dim ValeurPresente As Boolean
Dim i As Long
For i = 1 To oCollection.Count
If oCollection.Item(i) = strItem Then
ValeurPresente = True
Exit Sub
End If
Next i
If Not ValeurPresente Then oCollection.Add strItem
End Sub
Private Sub UserForm_Initialize()
Dim Cellule As Range
Dim balan As Range
Dim oCollection As New Collection
Dim i As Long
For Each Cellule In Feuil4.Range("a2:a" & Feuil4.Range("a" & Rows.Count).End(xlUp).Row)
AjouterItem oCollection, Cellule.Value
Next Cellule
For i = 1 To oCollection.Count
ComBox1.AddItem oCollection.Item(i)
Next i
End Sub
Private Sub ComBox1_Change()
Dim Cellule As Range
Dim oCollection As New Collection
Dim i As Long
ComBox2.Clear
' Itération sur chaque cellule de b et appel de la procédure d'ajout
For Each Cellule In Feuil4.Range("b2:b" & Feuil4.Range("b" & Rows.Count).End(xlUp).Row)
If Cellule(1, 0).Value = ComBox1.Value Then AjouterItem oCollection, Cellule.Value
Next Cellule
For i = 1 To oCollection.Count
ComBox2.AddItem oCollection.Item(i)
Next i
End Sub
Private Sub ComBox2_Change()
Dim oCollection As New Collection
Dim i As Long
Dim balan As Range
ComBox3.Clear
' Itération sur chaque cellule de c et appel de la procédure d'ajout
For Each balan In Feuil4.Range("c2:c" & Feuil4.Range("c" & Rows.Count).End(xlUp).Row)
If balan(1, 0).Value = ComBox2.Value Then AjouterItem oCollection, balan.Value
Next balan
For i = 1 To oCollection.Count
ComBox3.AddItem oCollection.Item(i)
Next i
End Sub
Private Sub ComBox3_Change()
Dim oCollection As New Collection
Dim i As Long
Dim calle As Range
ComBox4.Clear
' Itération sur chaque cellule de c et appel de la procédure d'ajout
For Each calle In Feuil4.Range("d2:d" & Feuil4.Range("d" & Rows.Count).End(xlUp).Row)
If calle(1, 0).Value = ComBox3.Value Then AjouterItem oCollection, calle.Value
Next calle
For i = 1 To oCollection.Count
ComBox4.AddItem oCollection.Item(i)
Next i
If ComBox4.ListCount > 1 Then
ComBox4.AddItem ("Tous")
End If
End Sub
Private Sub CommandButton2_Click()
UserForm2.Hide
End Sub
Private Sub Valider_Click()
If ComBox2 = "" Then
MsgBox "veuillez sélectionner une conditions à la case unité "
End If
If ComBox3 = "" Then
MsgBox "veuillez sélectionner une conditions à la case grosse machine "
End If
If ComBox4 = "" Then
MsgBox "veuillez sélectionner une conditions à la case périodicité "
End If
Dim Valx, Valy, Valz, i As Integer
Dim j As Integer
Dim critere As String
Dim critere1 As String
Dim critere2 As String
Sheets("Feuil3").Visible = True
Sheets("Feuil3").Select
Rows("2").Select
Selection.ClearContents
j = 2
Valx = Me.ComBox1.Value
Valy = Me.ComBox2.Value
Valz = Me.ComBox3.Value
'Affectation des variables critere et critere2 en fonction de la valeur des optionbutton
If OptionButton1 = True Then
critere = "oui"
ElseIf OptionButton2 = True Then
critere1 = "oui"
ElseIf OptionButton3 = True Then
critere2 = "oui"
Else
critere = "all"
End If
With Sheets("Feuil4")
For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If .Cells(i, 1) = Valx Then
If .Cells(i, 2) = Valy Then
If .Cells(i, 3) = Valz Or Valz = "Tous" Then
'Permet de comparer l'option cochée avec le contenu des colonnes de la feuille4
If .Cells(i, 21) = critere Or critere = "all" _
Or .Cells(i, 20) = critere1 Or critere1 = "all" _
Or .Cells(i, 22) = critere2 Or critere2 = "all" Then
Worksheets("Feuil4").Range("F" & i & ":G" & i & ",L" & i & ":S" & i).Copy (Worksheets("Feuil3").Range("A" & j))
j = j + 1
End If
End If
End If
End If
Next i
End With
Unload Me
MsgBox ("Veuillez masquer la Feuil3 en cliquant sur le logo de droite à la fin de cette opération!")
End Sub |
Partager