Private Sub CommandButton5_Click()
Dim e As Variant
Dim oFS, oFS1 As Object
Dim extract, extract1 As String
Dim wbextract As Workbook
Dim workcenter, PO, Plant, GMID, GMID1, d, quantity, basequantity, unitquantity, GMIDformat As Variant
Dim alternativebom As Integer
Dim iMaxAge, finalline As Integer
Dim i, j, x As Integer
With Application
.CutCopyMode = False
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
For i = 6 To 200
ThisWorkbook.Worksheets("Final").Activate
If Sheets("Final").Cells(i, 2) <> 0 Then
workcenter = Worksheets("Final").Range("A" & i).Value
Plant = Worksheets("Final").Range("B" & i).Value
PO = Worksheets("Final").Range("E" & i).Value
Worksheets("Macro").Range("B2") = PO
GMID = Worksheets("Final").Range("F" & i).Value
Worksheets("Macro").Range("B3") = GMID
quantity = Worksheets("Final").Range("H" & i).Value
Worksheets("Macro").Range("B4") = quantity
alternativebom = 1
If Sheets("Final").Cells(i, 7).Value Like "*DRM*" Then
GMIDformat = 1
Worksheets("Macro").Range("B14") = GMIDformat
End If
If Sheets("Final").Cells(i, 7).Value Like "*IBC*" Then
GMIDformat = 2
Worksheets("Macro").Range("B14") = GMIDformat
End If
If PO = "" Then GoTo Line
iMaxAge = 7
extract = "\\Rhnt01\das\Data\08_Facilities Operations\Produce_to_plan_&_Records_Production_Data\FP\Schedule Execution\Planning Form\BOM_PACK_DRUM.xlsx"
Set oFS = CreateObject("Scripting.FileSystemObject")
If DateDiff("d", oFS.GetFile(extract).DateLastModified, Now) > iMaxAge Then
MsgBox "Excel 'BOM_PACK_DRUM' pas à jour. Extract de nouveau (PACK_v6_APO)"
GoTo Line
End If
ThisWorkbook.Activate
Sheets("BOM template").Visible = True
Sheets("BOM template").Select
Sheets("BOM template").Copy After:=Sheets("Donnees")
Sheets("BOM template").Visible = False
Sheets("BOM template (2)").Select
Sheets("BOM template (2)").Name = "BOM GMID " & GMID
Set wbextract = Workbooks.Open(extract)
wbextract.Sheets("BOM").Activate
For j = 2 To 20000
If ActiveSheet.Cells(j, 1).Value = PO Then
quantity = ActiveSheet.Cells(j, 4)
unitquantity = ActiveSheet.Cells(j, 5)
End If
Next j
Set wbextract = Workbooks.Open(extract)
wbextract.Sheets("BOM").Activate
x = 10
For j = 2 To 20000
If ActiveSheet.Cells(j, 1).Value * 1 = PO Then
ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(3, 4) = PO
ActiveSheet.Cells(j, 2).Copy Destination:=ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(4, 4)
ActiveSheet.Cells(j, 10).Copy Destination:=ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(5, 4)
ActiveSheet.Cells(j, 3).Copy Destination:=ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(6, 4)
ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(7, 4) = quantity & " " & unitquantity
ActiveSheet.Cells(j, 11).Copy Destination:=ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(x, 2)
ActiveSheet.Cells(j, 6).Copy Destination:=ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(x, 3)
ActiveSheet.Cells(j, 7).Copy Destination:=ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(x, 4)
ActiveSheet.Cells(j, 8).Copy Destination:=ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(x, 5)
ActiveSheet.Cells(j, 9).Copy Destination:=ThisWorkbook.Sheets("BOM GMID " & GMID).Cells(x, 6)
x = x + 1
End If
Next j
ThisWorkbook.Activate
With Sheets("BOM GMID " & GMID)
.Select
.Range("B9:B50").Select
End With
finalline = Selection.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Row
With Sheets("BOM GMID " & GMID)
.Select
.Range("B10", "F" & finalline).Select
End With
Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
With Sheets("BOM GMID " & GMID)
.Select
.Range("A10", "C" & finalline).Select
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Sheets("BOM GMID " & GMID)
.Range("D1:D7").Select
End With
With Selection
.HorizontalAlignment = xlLeft
.MergeCells = False
End With
ActiveWorkbook.Worksheets("BOM GMID " & GMID).PrintOut From:=1, To:=1, Copies:=1
Application.DisplayAlerts = False
wbextract.Close savechanges:=False
ThisWorkbook.Sheets("BOM GMID " & GMID).Delete
Application.DisplayAlerts = True
If GMIDformat = 1 Then
Worksheets("Drum").PrintOut Copies:=1
Worksheets("Marquage 1-4").PrintOut Copies:=1
Worksheets("suivi poids futs 25").PrintOut Copies:=1
Sheets("Macro").Select
Dim y
y = Sheets("Macro").Cells(5, 2).Value
a = y / 40000
If y > 96 And GMID <> 4778 And GMID <> 11002972 And GMID <> 99075807 And GMID <> 127731 And GMID <> 1109845 Then
Worksheets("Marquage 4-8").PrintOut Copies:=1
End If
If y > 25 Then
Worksheets("suivi poids futs 50").PrintOut Copies:=1
End If
If y > 50 Then
Worksheets("suivi poids futs 75").PrintOut Copies:=1
End If
If y > 75 Then
Worksheets("suivi poids futs 100").PrintOut Copies:=1
End If
y = 0
Sheets("Macro").Select
Dim z
z = Sheets("Macro").Cells(3, 2).Value
If z = 237051 Then
Worksheets("StaraneF BRA").PrintOut Copies:=1
End If
y = 0
Sheets("Macro").Select
z = Sheets("Macro").Cells(3, 2).Value
If z = 97071375 Then
Worksheets("TRICEA").PrintOut Copies:=1
End If
End If
If GMIDformat = 2 Then
Worksheets("IBC").PrintOut Copies:=1
Worksheets("Marquage 1-4").PrintOut Copies:=1
Worksheets("suivi poids Ibcs 25").PrintOut Copies:=1
Sheets("IBC").Select
Dim w
w = Sheets("Macro").Cells(6, 2).Value
If w > 25 Then
Worksheets("suivi poids Ibcs 50").PrintOut Copies:=1
End If
If w > 50 Then
Worksheets("suivi poids Ibcs 75").PrintOut Copies:=1
End If
If w > 75 Then
Worksheets("suivi poids Ibcs 100").PrintOut Copies:=1
End If
End If
ElseIf Sheets("Final").Cells(i, 2) = 0 Then
GoTo Line
End If
Next i
Line:
With Application
.CutCopyMode = False
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
ThisWorkbook.Activate
Worksheets("Macro").Range("b2") = ""
Worksheets("Macro").Range("b3") = ""
Worksheets("Macro").Range("b4") = ""
Worksheets("Macro").Range("b14") = ""
y = 0
ThisWorkbook.Sheets("Macro").Select
ThisWorkbook.Sheets("Macro").Cells(1, 1).Select
End Sub