Sub CycleThrough()
P = Sheets("Barcode Packing List").Range("Q21").Value
'ActiveSheet.Unprotect P
Dim runws As Worksheet, barcodews As Worksheet
Dim a As Integer
Dim b As Integer
Dim d As Integer
Dim spool As Integer
Dim LR_wbSelectNew As Long
Dim row_num As Long
Dim e As Integer
Dim f As Integer
Set runws = Worksheets("Run Sheet")
Set barcodews = Worksheets("Barcode Packing List")
d = 1440 / (Range("Q3") / Range("AY1")) 'Calculates the max spools for 2-up
e = 720 / (Range("Q3") / Range("AY1")) 'Calculates the max spools for 1-up
f = (1440 / (Range("Q3") / Range("AY1"))) * 2 'Calculates the max spools for 4-up
'For 2-ups
If spool <> e Or spool <> f Then
spool = d
'All 1-ups
If Range("E1") = "504-002" Or _
Range("E1") = "308-001" Or _
Range("E1") = "318-101" Or _
Range("E1") = "318-001" Or _
Range("E1") = "318-002" Or _
Range("E1") = "318-102" Or _
Range("E1") = "625-022" Or _
Range("E1") = "318-103" Or _
Range("E1") = "626-022" Or _
Range("E1") = "304-001" Or _
Range("E1") = "321-001" Then
spool = e
End If
'Else
'All 4-ups
If Range("E1") = "OS-10MM" Or _
Range("E1") = "OS-10MM-SC" Or _
Range("E1") = "OS-10MM-2" Or _
Range("E1") = "273-100" Or _
Range("E1") = "273-400" Then
spool = f
End If
row_num = runws.Range("C8:W33").Find(what:=spool, LookIn:=xlValues, SearchOrder:=xlByRows).row '<----- This line seems to be wrong.
If barcodews.Range("B12").Value = "" Then GoTo exit_Sub
Application.ScreenUpdating = False
If spool >= 53 Then row_num = 33
For a = 12 To 35 Step 1
For c = 8 To row_num Step 1
'This compares the team letter in spool date code on Packing List with the team letter in Range("K1") on Run Sheet (2), matches the spool number with the number in columns C, I, Q, W.
'If the team letter matches, and the spool number matches, a "P" is put in the adjoining cell and column. An "S" if the spool number is not there.
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 3).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 4).Value = "P"
End If
If barcodews.Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And _
runws.Cells(c, 3).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 5).Value = barcodews.Cells(a, 5).Value 'This will put short footage in the appropriate cell if needed.
End If
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 3).Value <> Right(barcodews.Cells(a, 2).Value, 2) And _
runws.Cells(c, 4).Value <> "P" Then
runws.Cells(c, 4).Value = "S"
End If
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 9).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 10).Value = "P"
End If
If barcodews.Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And _
runws.Cells(c, 9).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 11).Value = barcodews.Cells(a, 5).Value
End If
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 9).Value <> Right(barcodews.Cells(a, 2).Value, 2) And _
runws.Cells(c, 10).Value <> "P" Then
runws.Cells(c, 10).Value = "S"
End If
Next c
Next a
If d < 53 Then GoTo exit_Sub
'Else
row_num = runws.Range("C8:W33").Find(what:=spool, LookIn:=xlValues, SearchOrder:=xlByRows).row '<----- This line seems to be wrong.
If spool >= 105 Then row_num = 33
For a = 12 To 35 Step 1
For c = 8 To row_num Step 1
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 17).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 18).Value = "P"
End If
If barcodews.Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And _
runws.Cells(c, 17).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 19).Value = barcodews.Cells(a, 5).Value
End If
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 17).Value <> Right(barcodews.Cells(a, 2).Value, 2) And _
runws.Cells(c, 18).Value <> "P" Then
runws.Cells(c, 18).Value = "S"
End If
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 23).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 24).Value = "P"
End If
If barcodews.Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And _
runws.Cells(c, 23).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 25).Value = barcodews.Cells(a, 5).Value
End If
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 23).Value <> Right(barcodews.Cells(a, 2).Value, 2) And _
runws.Cells(c, 24).Value <> "P" Then
runws.Cells(c, 24).Value = "S"
End If
Next c
Next a
If d < 105 Then GoTo exit_Sub
For a = 12 To 35 Step 1
For c = 8 To row_num Step 1
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 31).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 32).Value = "P"
End If
If barcodews.Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And _
runws.Cells(c, 31).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 33).Value = barcodews.Cells(a, 5).Value
End If
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 31).Value <> Right(barcodews.Cells(a, 2).Value, 2) And _
runws.Cells(c, 32).Value <> "P" Then
runws.Cells(c, 32).Value = "S"
End If
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 37).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 38).Value = "P"
End If
If barcodews.Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And _
runws.Cells(c, 37).Value = Right(barcodews.Cells(a, 2).Value, 2) Then
runws.Cells(c, 39).Value = barcodews.Cells(a, 5).Value
End If
If runws.Range("AK1").Value = Mid(barcodews.Cells(a, 2), 7, 1) And _
runws.Cells(c, 37).Value <> Right(barcodews.Cells(a, 2).Value, 2) And _
runws.Cells(c, 38).Value <> "P" Then
runws.Cells(c, 38).Value = "S"
End If
Next c
Next a
With runws.Range("D8").CurrentRegion
LR_wbSelectNew = .Rows(.Rows.Count).row
End With
End If: 'End If: 'End If
exit_Sub:
Application.ScreenUpdating = True
'ActiveSheet.Protect P
End Sub
Bookmarks