+ Reply to Thread
Results 1 to 27 of 27

Create batches based on set quantities and order by earliest date

Hybrid View

  1. #1
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Create batches based on set quantities and order by earliest date

    Hello all,

    I have a list of orders for skateboards with the model, date, and quantity for each order. Unfortunately, I can only make 25 skateboards a week. Is there a way I can take the data and create a production schedule with batches of 25 per model and rank them by earliest dates fist?

    Thanks!

    Ocdawg
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    Dear OCdawg:

    First order first serve or you want to lump together the same model orders in order to optimize production?

  3. #3
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    Thanks for responding - I'd. Like to rank them by model.

    Ocdawg

  4. #4
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    Dear Ocadawg:

    I did this manually just to show if that would be a desirable output. I did realize that it should have started with model 33T because it has the oldest date. It would be taken into account on the real scheme.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    Wow, that looks great. Is there a formula to do that?

    Ocdawg

  6. #6
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    I will work on over the weekend...

  7. #7
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    Below please find the macro that will produce the output in TRIAL
    I have included the workbook as well
    Have a nice weekend!!

    Set sh1 = Sheets("trial")
    r1 = 3
    r1min = 3
    wl = 0
    wek = 5
    maxwl = 25
    sh1.Cells(r1, "D") = "Week 1"
    While sh1.Cells(r1, 1) <> ""
     lt = sh1.Cells(r1, "C")
     wl = wl + lt
     If wl > maxwl Then
       If lt - wl + maxwl > 0 Then sh1.Cells(r1, wek) = lt - wl + maxwl
       lt = wl - maxwl
       wek = wek + 1
       wl = lt
       If lt >= maxwl Then
         sh1.Cells(r1, wek) = maxwl
         wek = wek + 1
         lt = lt - maxwl
         wl = lt
       End If
     End If
      If lt > 0 Then sh1.Cells(r1, wek) = lt
      sh1.Cells(r1, "D") = "Week " & wek - 4
     r1 = r1 + 1
    Wend
    
    End Sub
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    Very nice!

    You rock!

  9. #9
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    Ok mark it as solved if you are satisfied. It was a good brain challenge. Any time

  10. #10
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    Just a warning, it does take care of smaller orders but if you have an order over 80 it needs extra coding... your call

  11. #11
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    What is the extra coding?

  12. #12
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    Sub weekly()
    
    Set sh1 = Sheets("trial")
    r1 = 3
    r1min = 3
    wl = 0
    wek = 5
    maxwl = 25
    sh1.Cells(r1, "D") = "Week 1"
    While sh1.Cells(r1, 1) <> ""
     lt = sh1.Cells(r1, "C")
     wl = wl + lt
     If wl > maxwl Then
       If lt - wl + maxwl > 0 Then sh1.Cells(r1, wek) = lt - wl + maxwl
       lt = wl - maxwl
       wek = wek + 1
       wl = lt
       While lt >= maxwl
         sh1.Cells(r1, wek) = maxwl
         wek = wek + 1
         lt = lt - maxwl
         wl = lt
       Wend
     End If
      If lt > 0 Then sh1.Cells(r1, wek) = lt
      sh1.Cells(r1, "D") = "Week " & wek - 4
     r1 = r1 + 1
    Wend
    
    End Sub
    With this change the macro can now handle big orders... give it a try..

  13. #13
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    What do I do after adding the code to a new macro? I hit run, but it only prints "Week 1" on the trial sheet. I'm on Excel 2007.

    Thanks,

    Ocdawg

  14. #14
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    I tried this improved macro with a lot size of 100 and it worked. It is writing to the SHEET "TRIAL". I dont see any command that is not compatible with your execl version. Please write if it does not work for you but send me your actual data sheet. It must start in row 3.
    Sub weekly()
    
    Set sh1 = Sheets("trial")
    sh1.Range("d3:v40").ClearContents
    r1 = 3
    r1min = 3
    wl = 0
    wek = 5
    maxwl = 25
    sh1.Cells(r1, "D") = "Week 1"
    While sh1.Cells(r1, 1) <> ""
      lt = sh1.Cells(r1, "C")
      wl = wl + lt
     
      While wl > maxwl
        If lt - wl + maxwl > 0 Then sh1.Cells(r1, wek) = lt - wl + maxwl
        lt = wl - maxwl
        wek = wek + 1
        wl = lt
      Wend
       
      If lt > 0 Then sh1.Cells(r1, wek) = lt
      sh1.Cells(r1, "D") = "Week " & wek - 4
      r1 = r1 + 1
    Wend
    
    End Sub
    ot

  15. #15
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    Hello,

    Perhaps I am not executing it properly. I've attached the file I am working with. It only prints "Week 1" on the Trial sheet.

    Thanks!

    Ocdawg
    Attached Files Attached Files

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,663

    Re: Create batches based on set quantities and order by earliest date

    Try the attached.
    Sub test()
        Dim a, b, i As Long, ttl As Long, n As Long, myWk As Long
        Const maxJob As Long = 25
        With Sheets("sheet1")
            a = Sheets("sheet1").[a3].CurrentRegion.Value
            ReDim b(1 To 10000, 1 To 4): myWk = 1: n = 1
            b(1, 1) = "Week" & myWk: VSortM a, 1, UBound(a, 1), 2
            For i = 1 To UBound(a, 1)
                If a(i, 3) <> 0 Then
                    If ttl + a(i, 3) <= maxJob Then
                        n = n + 1
                        b(n, 2) = a(i, 1): b(n, 3) = a(i, 2): b(n, 4) = a(i, 3)
                        ttl = ttl + a(i, 3)
                        If ttl = maxJob Then
                            myWk = myWk + 1: n = n + 1
                            b(n, 1) = "Week" & myWk: ttl = 0
                        End If
                    Else
                        n = n + 1
                        b(n, 2) = a(i, 1): b(n, 3) = a(i, 2)
                        b(n, 4) = maxJob - ttl: ttl = b(n, 4)
                        myWk = myWk + 1: n = n + 1
                        b(n, 1) = "Week" & myWk
                        a(i, 3) = a(i, 3) - ttl: ttl = 0: i = i - 1
                    End If
                End If
            Next
            .Columns("f:j").ClearContents
            .[f2].Resize(n, 4) = b
        End With
    End Sub
    
    Sub VSortM(ary, LB, UB, ref)
        Dim i As Long, ii As Long, iii As Long, M, temp
        i = UB: ii = LB
        M = ary(Int((LB + UB) / 2), ref)
        Do While ii <= i
            Do While ary(ii, ref) < M: ii = ii + 1: Loop
            Do While ary(i, ref) > M: i = i - 1: Loop
            If ii <= i Then
                For iii = LBound(ary, 2) To UBound(ary, 2)
                    temp = ary(ii, iii): ary(ii, iii) = ary(i, iii): ary(i, iii) = temp
                Next
                i = i - 1: ii = ii + 1
            End If
        Loop
        If LB < i Then VSortM ary, LB, i, ref
        If ii < UB Then VSortM ary, ii, UB, ref
    End Sub
    Attached Files Attached Files

  17. #17
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    Hi, I think I found the reason it was not working. Originally I had copied the data into TRIAL manually. Nevertheless, if you want to start in a clean worksheet, TRIAL, I added the necessary code. Data is to be in "SHEET1".

    Sub weekly()
    Set sh0 = ThisWorkbook.Sheets("sheet1")
    Set sh1 = ThisWorkbook.Sheets("trial")
    sh1.Cells.ClearContents
    r1 = 3
    r0 = r1
    r1min = 3
    wl = 0
    wek = 5
    maxwl = 25
    sh1.Cells(r1, "D") = "Week 1"
    
    While sh0.Cells(r0, 1) <> ""
      For j = 1 To 3
        sh1.Cells(r1, j) = sh0.Cells(r0, j)
      Next j
     lt = sh1.Cells(r1, "C")
     wl = wl + lt
     While wl > maxwl
       If lt - wl + maxwl > 0 Then sh1.Cells(r1, wek) = lt - wl + maxwl
       lt = wl - maxwl
       wek = wek + 1
       wl = lt
     Wend
     
      If lt > 0 Then sh1.Cells(r1, wek) = lt
      sh1.Cells(r1, "D") = "Week " & wek - 4
     r1 = r1 + 1
     r0 = r0 + 1
    Wend
    
    For c = 1 To wek - 4
      sh1.Cells(1, c + 4) = "W " & WorksheetFunction.Text(c, "00")
    Next c
    
     sh1.Cells(3, 1).Select
     ActiveCell.CurrentRegion.EntireColumn.AutoFit
        
    End Sub

  18. #18
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    You were right, that fixed it! I appreciate your help.

    What code would I need to add if I wanted to add columns that list the customer, purchase order and sales order? See attached. Is there a way to have the data output into a vertical display?

    Thanks so much.

    Ocdawg
    Attached Files Attached Files

  19. #19
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    I changed the code to fit the 3 new fields.

    Could you elaborate on the "vertical display"?
    Please include the desired output format (just an small example) so the output can be formatted the way you want...
    Attached Files Attached Files

  20. #20
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    Check the VERTICAL tab. Is that what you mean by vertical. the ** is when the order is completed.
    Attached Files Attached Files

  21. #21
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    Yes, that is the vertical type layout. But it doesn't look like it's breaking into groups of 25.

    Ocdawg

  22. #22
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    You are right. It was working but showing the wrong parameter. Take a look at it now...
    Attached Files Attached Files

  23. #23
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    Very cool!

    What code would I add to bring it back to keeping the model groups together for batching?

    Ocdawg

  24. #24
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Create batches based on set quantities and order by earliest date

    The easiest way is to sort the orders by MODEL and then by date so just add the red Highlighted line.

    Sub weekly()
    Set sh0 = ThisWorkbook.Sheets("sheet1")
    Set sh1 = ThisWorkbook.Sheets("trial")
    Set sh2 = ThisWorkbook.Sheets("vertical")
    sh1.Cells.Delete
    sh2.Cells.j
    
    r1min = 3
    r1 = 3
    r0 = r1
    r2 = 5
    wl = 0
    
    wek = 8
    maxwl = 25
    flds = 6
    sh1.Cells(r1, "G") = "W 1"
    
    While sh0.Cells(r0, 1) <> ""
      For j = 1 To flds
        sh1.Cells(r0, j) = sh0.Cells(r0, j)
        sh1.Cells(r0, j).Interior.Color = sh0.Cells(r0, j).Interior.Color
      Next j
      r0 = r0 + 1
    Wend
    
    
        With sh1.Sort
            .SortFields.Clear
            .SortFields.Add Key:=Range("D" & r1min & ":D" & r0 - 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
            .SortFields.Add Key:=Range("E" & r1min & ":E" & r0 - 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
            .SetRange Range("A" & r1min & ":F" & r0 - 1)
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
    
    r1 = r1min
    r2last = r2
    While sh1.Cells(r1, 1) <> ""
     lt = sh1.Cells(r1, flds)
     wl = wl + lt
     While wl > maxwl
       If lt - wl + maxwl > 0 Then
         wo = lt - wl + maxwl
         sh1.Cells(r1, wek) = wo
         sh1.Cells(r1, wek).Interior.Color = sh1.Cells(r1, "D").Interior.Color
         If wek <> ant Then
          sh2.Cells(r2, 1) = "Week " & wek - flds - 1
          ant = wek
        End If
         If sh1.Cells(r1, 3) <> old Then
           sh2.Cells(r2last, 8) = "**"
           old = sh1.Cells(r1, 3)
         End If
         For j = 1 To 4
           sh2.Cells(r2, j + 1) = sh1.Cells(r1, j)
         Next j
         sh2.Cells(r2, 6) = sh1.Cells(r1, 6)
         sh2.Cells(r2, 7) = wo
         r2last = r2
         r2 = r2 + 1
       End If
       lt = wl - maxwl
       wek = wek + 1
       r2 = r2 + 1
       wl = lt
     Wend
     
      If lt > 0 Then
        sh1.Cells(r1, wek) = lt
        sh1.Cells(r1, wek).Interior.Color = sh1.Cells(r1, "D").Interior.Color
        If wek <> ant Then
          sh2.Cells(r2, 1) = "Week " & wek - flds - 1
          ant = wek
        End If
           
        If sh1.Cells(r1, 3) <> old Then
          sh2.Cells(r2last, 8) = "**"
          old = sh1.Cells(r1, 3)
        End If
        For j = 1 To 4
          sh2.Cells(r2, j + 1) = sh1.Cells(r1, j)
        Next j
        sh2.Cells(r2, 6) = sh1.Cells(r1, 6)
        sh2.Cells(r2, 7) = lt
        r2last = r2
        r2 = r2 + 1
      End If
     
      sh1.Cells(r1, "G") = "W " & wek - flds - 1
      sh1.Cells(r1, "G").Interior.Color = sh1.Cells(r1, "D").Interior.Color
    
     r1 = r1 + 1
    
    Wend
    sh2.Cells(r2last, 8) = "**"
    For c = 1 To wek - flds - 1
      sh1.Cells(1, c + flds + 1) = "W " & WorksheetFunction.Text(c, "00")
    Next c
     sh1.Select
     Range("A3").Select
     ActiveCell.CurrentRegion.EntireColumn.AutoFit
        
    End Sub

  25. #25
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    Great, thanks. Do you do all this by writing code or recording macros?

    How do I mark as solved?

    Ocdawg

  26. #26
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394
    Quote Originally Posted by Ocdawg View Post
    Great, thanks. Do you do all this by writing code or recording macros?

    How do I mark as solved?

    Ocdawg
    I did this by writing code but from time to time I record an action to save time and learn.

  27. #27
    Registered User
    Join Date
    01-20-2018
    Location
    OC
    MS-Off Ver
    2007
    Posts
    14

    Re: Create batches based on set quantities and order by earliest date

    Hi rcm,

    I see this sorts alphabetically. What would I need to do if I wanted to sort by oldest average date of order?

    Ocdawg

+ 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. How to enter a value for the first row based on the earliest date
    By stan255 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-14-2017, 10:50 PM
  2. Add up order quantities and show date required summary
    By miked79 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-04-2017, 10:02 AM
  3. Moving to the date in a row based on earliest date in a column.
    By BDBJ1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-19-2016, 11:34 AM
  4. LookUp based earliest date (2007)
    By D_N_L in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-15-2012, 08:19 AM
  5. [SOLVED] macro to create rows of data based on divided quantities
    By MSApprentice in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2011, 12:19 PM
  6. Find earliest date based on certain criteria
    By SeanKosmann in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 01-26-2010, 11:32 AM
  7. Find Earliest Date based on conditions
    By ShredDude in forum Excel General
    Replies: 6
    Last Post: 07-14-2007, 01:56 PM

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