+ Reply to Thread
Results 1 to 3 of 3

Filling in consecutive cells up to different max numbers.

Hybrid View

  1. #1
    Registered User
    Join Date
    05-08-2017
    Location
    USA
    MS-Off Ver
    2016
    Posts
    4

    Filling in consecutive cells up to different max numbers.

    Hi everyone,

    The problem I am having is shown on "Run Sheet". When the Run Sheet is activated, a macro starts that looks at the Packing List, and matches the spool number, (the last two digits in the "spool date code"), with the corresponding number on the Run Sheet. If the numbers match, the adjacent cell in the "Pack or Scrap" column gets a "P". All other cells up to the max number of spools gets an "S", until the spool number is produced. The sheet "Run Sheet (2) shows how the correct result looks. On the Run Sheet, the macro finds the max number (58) on row 10 and stops there. (I'm not sure how to have it search the columns.) All of the numbers from 11 - 58 should be highlighted yellow with an S. The code I am using follows...

    Sub CycleThrough()
    Formula: copy to clipboard
    P = Sheets("Barcode Packing List").Range("Q21").Value
    'ActiveSheet.Unprotect P

    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



    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 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

    '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

    row_num = Worksheets("Run Sheet").Range("C8:W33").Find(what:=spool, LookIn:=xlValues, SearchOrder:=xlByRows).row '<----- I know I need to search columns, but not sure how.


    If Worksheets("Barcode Packing List").Range("B12").Value = "" Then Exit Sub
    Application.ScreenUpdating = False


    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 Worksheets("Run Sheet").Range("AK1").Value = Mid(Sheet3.Cells(a, 2), 7, 1) And Worksheets("Run Sheet (2)").Cells(c, 3).Value = Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) Then _
    Worksheets("Run Sheet").Cells(c, 4).Value = "P"

    If Worksheets("Barcode Packing List").Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And Worksheets("Run Sheet").Cells(c, 3).Value = Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) Then _
    Worksheets("Run Sheet").Cells(c, 5).Value = Worksheets("Barcode Packing List").Cells(a, 5).Value 'This will put short footage in the appropriate cell if needed.

    If Worksheets("Run Sheet").Range("AK1").Value = Mid(Sheet3.Cells(a, 2), 7, 1) And Worksheets("Run Sheet").Cells(c, 3).Value <> Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) And Worksheets("Run Sheet").Cells(c, 4).Value <> "P" Then _
    Worksheets("Run Sheet").Cells(c, 4).Value = "S"


    If Worksheets("Run Sheet").Range("AK1").Value = Mid(Sheet3.Cells(a, 2), 7, 1) And Worksheets("Run Sheet").Cells(c, 9).Value = Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) Then _
    Worksheets("Run Sheet").Cells(c, 10).Value = "P"

    If Worksheets("Barcode Packing List").Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And Worksheets("Run Sheet").Cells(c, 9).Value = Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) Then _
    Worksheets("Run Sheet").Cells(c, 11).Value = Worksheets("Barcode Packing List").Cells(a, 5).Value

    If Worksheets("Run Sheet").Range("AK1").Value = Mid(Sheet3.Cells(a, 2), 7, 1) And Worksheets("Run Sheet").Cells(c, 9).Value <> Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) And Worksheets("Run Sheet").Cells(c, 10).Value <> "P" Then _
    Worksheets("Run Sheet").Cells(c, 10).Value = "S"

    Next c
    Next a

    If d < 53 Then _
    Exit Sub
    'Else

    For a = 12 To 35 Step 1
    For c = 8 To row_num Step 1


    If Worksheets("Run Sheet").Range("AK1").Value = Mid(Sheet3.Cells(a, 2), 7, 1) And Worksheets("Run Sheet").Cells(c, 17).Value = Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) Then _
    Worksheets("Run Sheet").Cells(c, 18).Value = "P"

    If Worksheets("Barcode Packing List").Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And Worksheets("Run Sheet").Cells(c, 17).Value = Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) Then _
    Worksheets("Run Sheet").Cells(c, 19).Value = Worksheets("Barcode Packing List").Cells(a, 5).Value

    If Worksheets("Run Sheet").Range("AK1").Value = Mid(Sheet3.Cells(a, 2), 7, 1) And Worksheets("Run Sheet").Cells(c, 17).Value <> Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) And Worksheets("Run Sheet").Cells(c, 18).Value <> "P" Then _
    Worksheets("Run Sheet").Cells(c, 18).Value = "S"



    If Worksheets("Run Sheet").Range("AK1").Value = Mid(Sheet3.Cells(a, 2), 7, 1) And Worksheets("Run Sheet").Cells(c, 23).Value = Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) Then _
    Worksheets("Run Sheet").Cells(c, 24).Value = "P"

    If Worksheets("Barcode Packing List").Cells(a, 5).Value <> Worksheets("Specs").Range("B10") And Worksheets("Run Sheet").Cells(c, 23).Value = Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) Then _
    Worksheets("Run Sheet").Cells(c, 25).Value = Worksheets("Barcode Packing List").Cells(a, 5).Value

    If Worksheets("Run Sheet").Range("AK1").Value = Mid(Sheet3.Cells(a, 2), 7, 1) And Worksheets("Run Sheet").Cells(c, 23).Value <> Right(Worksheets("Barcode Packing List").Cells(a, 2).Value, 2) And Worksheets("Run Sheet").Cells(c, 24).Value <> "P" Then _
    Worksheets("Run Sheet").Cells(c, 24).Value = "S"


    Next c
    Next a


    'For a = 12 To 35 Step 1
    'For c = 8 To row_num Step 1






    'Next c
    'Next a

    With Worksheets("Run Sheet").Range("D8").CurrentRegion
    LR_wbSelectNew = .Rows(.Rows.Count).row
    End With

    End If: 'End If: 'End If
    Application.ScreenUpdating = True
    'ActiveSheet.Protect P
    End Sub
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Filling in consecutive cells up to different max numbers.

    hi,

    your row_num was for the next block and you should have gone trough the first full block until 33 instead of 10

    i cleaned it up but kept most so you can easely find your way back

    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
    Attached Files Attached Files
    Last edited by Joske920; 03-28-2021 at 08:05 AM. Reason: fixed your screenupdating when exiting urly
    Please be as complete as possible in your asking so it may save use all the time to rework the solution because you didn't give all the requirements. If you have a layout in mind please work it out first so we can adapt our solution to it. Thanks.
    If you have been helped, maybe you could click the *

  3. #3
    Registered User
    Join Date
    05-08-2017
    Location
    USA
    MS-Off Ver
    2016
    Posts
    4

    Re: Filling in consecutive cells up to different max numbers.

    Joske920,

    Thank you so much! This works perfectly, exactly how I wanted it to. The solution makes sense now that I see it...Lesson learned. Thanks again!
    And thanks for doing some cleaning on my code. I'm still learning, and appreciate all the help I can get.
    Last edited by GreggR57; 03-28-2021 at 01:16 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Filling cells based on a range of numbers. Pop up maybe?
    By gjclmb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-03-2021, 02:55 PM
  2. Locate Cells with 5 consecutive numbers or more
    By Demoniacs in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-01-2020, 07:18 PM
  3. [SOLVED] Compare consecutive numbers between 2 cells
    By Najwa_X in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-17-2020, 09:40 AM
  4. [SOLVED] Trying to extract text cells at the first instance of four consecutive numbers
    By portokie in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 07-15-2016, 06:32 PM
  5. How to fill a column of cells with consecutive numbers ?
    By M-Ray in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2013, 09:59 AM
  6. Automtically filling non consecutive cells
    By pkc23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2009, 06:29 PM
  7. filling cells acording to the first 3 numbers
    By pmarques in forum Excel General
    Replies: 1
    Last Post: 09-09-2005, 07:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1