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
| Private Sub BtVldcreation_Click()
Dim tabBDD()
Dim i&, annee&
Set wsBDD = Worksheets("retour")
Set dicoimputation = CreateObject("Scripting.Dictionary")
With wsBDD
tabBDD = Range(.Cells(4, 1), .Cells(.Cells(Rows.Count, 1).End(xlUp).Row, 21))
End With
If NbTypeMachine = 0 Then
NbTypeMachinex = 0
Else
If NbTypeMachine >= 1 Then
NbTypeMachinex = NbTypeMachine - 1
End If
End If
If NbAnnee = 0 Then
NbAnneex = 0
Else
If NbAnnee >= 1 Then
NbAnneex = NbAnnee - 1
End If
End If
If NbProvenance = 0 Then
NbProvenancex = 0
Else
If NbProvenance >= 1 Then
NbProvenancex = NbProvenance - 1
End If
End If
'Boucle qui sert à savoir dans quel cas nous nous trouvons afin de prendre en compte le nombre de critère désiré
For i = 0 To NbTypeMachinex
For j = 0 To NbAnneex
For k = 0 To NbProvenancex
If NbTypeMachine = 0 And NbAnnee = 0 Then ' Seul le critère Provenance est renseigné
For ctlBDD = LBound(tabBDD) To UBound(tabBDD)
If (tabBDD(ctlBDD, 6)) = Me.Controls("ComboBox" & 7 + k) Then
If (tabBDD(ctlBDD, 13)) <> "" Then dicoimputation(tabBDD(ctlBDD, 13)) = ""
End If
Next ctlBDD
ElseIf NbProvenance = 0 And NbTypeMachine = 0 Then ' Seul le critère Année est renseigné
For ctlBDD = LBound(tabBDD) To UBound(tabBDD)
annee = Me.Controls("ComboBox" & 4 + j)
If (tabBDD(ctlBDD, 2)) = annee Then
If (tabBDD(ctlBDD, 13)) <> "" Then dicoimputation(tabBDD(ctlBDD, 13)) = ""
End If
Next ctlBDD
ElseIf NbProvenance = 0 And NbAnnee = 0 Then ' Seul le critère Type Machine est renseigné
For ctlBDD = LBound(tabBDD) To UBound(tabBDD)
If (tabBDD(ctlBDD, 1)) = Me.Controls("ComboBox" & 1 + i) Then
If (tabBDD(ctlBDD, 13)) <> "" Then dicoimputation(tabBDD(ctlBDD, 13)) = ""
End If
Next ctlBDD
ElseIf NbTypeMachine = 0 Then ' Seul le critère Type Machine n' est pas renseigné
For ctlBDD = LBound(tabBDD) To UBound(tabBDD)
annee = Me.Controls("ComboBox" & 4 + j)
If (tabBDD(ctlBDD, 2)) = annee And (tabBDD(ctlBDD, 6)) = Me.Controls("ComboBox" & 7 + k) Then
If (tabBDD(ctlBDD, 13)) <> "" Then dicoimputation(tabBDD(ctlBDD, 13)) = ""
End If
Next ctlBDD
ElseIf NbAnnee = 0 Then ' Seul le critère Année n' est pas renseigné
For ctlBDD = LBound(tabBDD) To UBound(tabBDD)
If (tabBDD(ctlBDD, 1)) = Me.Controls("ComboBox" & 1 + i) _
And (tabBDD(ctlBDD, 6)) = Me.Controls("ComboBox" & 7 + k) Then
If (tabBDD(ctlBDD, 13)) <> "" Then dicoimputation(tabBDD(ctlBDD, 13)) = ""
End If
Next ctlBDD
ElseIf NbProvenance = 0 Then ' Seul le critère Provenance n' est pas renseigné
For ctlBDD = LBound(tabBDD) To UBound(tabBDD)
annee = Me.Controls("ComboBox" & 4 + j)
If (tabBDD(ctlBDD, 1)) = Me.Controls("ComboBox" & 1 + i) And (tabBDD(ctlBDD, 2)) = annee Then
If (tabBDD(ctlBDD, 13)) <> "" Then dicoimputation(tabBDD(ctlBDD, 13)) = ""
End If
Next ctlBDD
Else
For ctlBDD = LBound(tabBDD) To UBound(tabBDD) 'Tous les critères sont renseignés
annee = Me.Controls("ComboBox" & 4 + j)
If (tabBDD(ctlBDD, 1)) = Me.Controls("ComboBox" & 1 + i) And (tabBDD(ctlBDD, 2)) = annee _
And (tabBDD(ctlBDD, 6)) = Me.Controls("ComboBox" & 7 + k) Then
If (tabBDD(ctlBDD, 13)) <> "" Then dicoimputation(tabBDD(ctlBDD, 13)) = ""
End If
Next ctlBDD
End If
Next k
Next j
Next i
Unload Me
Sheets.Add.Move After:=Sheets(Sheets.Count)
Nom = InputBox("Comment souhaitez vous nommer cette feuille?")
Sheets(Sheets.Count).Name = Nom
[A2].Resize(dicoimputation.Count) = Application.Transpose(dicoimputation.keys)
End Sub |
Partager