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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
Sub Macro1()
Dim Cls_1 As Workbook
Dim Cls_2 As Workbook
Dim Fe_Produits As Worksheet
Dim Fe_Bordereau As Worksheet
Dim Fe_cablage As Worksheet
Dim Chemin As String
Dim Nom As String
Dim Nom2 As String
Dim Compteur_1 As Integer, Compteur_2 As Integer, compteur_3 As Integer, compteur_4 As Integer, compteur_5 As Integer
Dim I As Integer
Dim J As Integer
Dim K As Integer, x As Integer
Dim DerLg As Integer
Dim nb As Integer
Dim capa1 As String, capa2 As String
'''''''''''''''''Nom du fichier'''''''
Set Cls_1 = ThisWorkbook
Nom = Cls_1.Name
Nom = Left(Cls_1.Name, InStr(Cls_1.Name, ".xlsm") - 1)
Cls_1.Worksheets("bordereau").Range("F4") = Split(Nom, "_")(2)
Nom2 = Split(Nom, "_")(4)
Cls_1.Worksheets("bordereau").Range("F7") = Mid(Nom2, 1, 2) & "/" & Mid(Nom2, 3, 2) & "/" & Mid(Nom2, 5, 2)
'''''''''''ouvrir le fichier referentiel''''''''''''''''''''''''''''
Chemin = Cls_1.path
If Right(Chemin, 1) <> "\" Then Chemin = Chemin & "\"
'suppression des 3 premières lettres
Nom = Right(Cls_1.Name, Len(Cls_1.Name) - 8)
'variable objet "Workbook"
Set Cls_2 = Application.Workbooks.Open(Chemin & "referentiel" & Nom)
Set Fe_Produits = Cls_1.Worksheets("Liste Produits Stockés")
Set Fe_Bordereau = Cls_1.Worksheets("bordereau")
Set Fe_cablage = Cls_2.Worksheets("cablage")
Set Fe_référencés = Cls_1.Worksheets("Liste Produits Référencés")
With Fe_cablage
DerLg = .Cells(.Rows.Count, 1).End(xlUp).Row
I = DerLg
J = I - 1
K = 25
Do While .Cells(I, 1).Interior.ColorIndex = .Cells(J, 1).Interior.ColorIndex
I = I - 1
J = J - 1
Loop
For Compteur_1 = DerLg To I Step -1
Set trouve = Range("A2", "A" & J).Cells.Find(what:=.Cells(Compteur_1, 1).Value)
If (trouve Is Nothing) Then
Fe_Bordereau.Cells(K, 1) = Fe_Produits.Cells(6, 1)
K = K + 1
Fe_Bordereau.Cells(K, 1) = Fe_Produits.Cells(8, 1)
Else
Set trouve1 = Range("B2", "B" & J).Cells.Find(what:=.Cells(Compteur_1, 2).Value)
If (Not trouve1 Is Nothing) Then
If ((.Cells(Compteur_1, 13).Value = "break-out SMF") Or (.Cells(Compteur_1, 13).Value = "break-out MMF")) Then
Fe_Bordereau.Cells(K, 1) = Fe_Produits.Cells(7, 1)
Else
If ((.Cells(Compteur_1, 13).Value = "jarretière SMF") Or (.Cells(Compteur_1, 13).Value = "jarretière MMF")) Then
Fe_Bordereau.Cells(K, 1) = Fe_Produits.Cells(7, 1)
End If
End If
End If
End If
If (Fe_Bordereau.Cells(K, 1) = "") Then
K = K - 1
End If
derl = Fe_Produits.Cells(.Rows.Count, 1).End(xlUp).Row
Set trouve2 = Range("P2", "P" & J).Cells.Find(what:=.Cells(Compteur_1, 16).Value)
If (Not trouve2 Is Nothing) Then
If .Cells(Compteur_1, 13).Value = "break-out" Then
capa1 = Cells(Compteur_1, 23).Value
capa2 = (Cells(Compteur_1, 14).Value) * 2
For compteur_3 = 9 To derl
Set trouve3 = Fe_Produits.Cells(compteur_3, 1).Find(what:=capa1 And capa2)
If (Not trouve3 Is Nothing) Then
Fe_Bordereau.Cells(K, 1) = Fe_Produits.Cells(compteur_3, 1)
End If
Next compteur_3
End If
End If
K = K + 1
Next Compteur_1
End With
With Fe_Bordereau
Derg = .Cells(.Rows.Count, 1).End(xlUp).Row
compteur_4 = 25
Do
nb = 1
For compteur_5 = compteur_4 + 1 To Derg
If (.Cells(compteur_4, 1) = .Cells(compteur_5, 1)) Then
nb = nb + 1
Fe_Bordereau.Cells(compteur_4, 2) = nb
Fe_Bordereau.Cells(compteur_5, 1) = ""
End If
Next compteur_5
compteur_4 = compteur_4 + 1
Loop Until (Fe_Bordereau.Cells(compteur_4, 1) = "")
End With
End Sub |
Partager