Sorting Automation for Pallets and Boxes

Gotchaman

New Member
Joined
Jul 15, 2011
Messages
25
At our warehouse we ship hundreds of boxes everyday. Warehouse guys load boxes on pallets and then scan pallet ID's and box ID's, then upload the scanned data to the system.
When I download the records, it is all in one line containing pallet IDs and Box IDs as shown below. Pallets ID's (bold in this example) are in numerical order.
So, the A1 value is always the first pallet ID.
Excel Workbook
A
1000000004352
2136016484001
3018490316001
4017023735001
5018619171001
6018619165001
7017068487001
8000000004353
9017070233001
10017053072001
11017052845001
12018617358001
13017052885001
14136028205001
15017053056001
16018210505001
17000000004354
18136004557001
19017060663001
20017070806001
21017060659001
22017044247001
23018040312001
24017060667001
25000000004355
26136027691001
27017067792001
28017161670001
29017060246001
Before
Excel 2007

My goal is to separate them by pallets as shown below. Boxes don't need to be sorted. Sometimes there are 10 pallets, sometimes 20 pallets, you never know. So the loop must work for as long as there are pallets.

Can someone please help with an automate job to do this? We have been doing this manually (find next pallet ID, cut and paste on the next column) and looking for a faster way. Thank you very much!
Excel Workbook
ABCD
1000000004352000000004353000000004354000000004355
2136016484001017070233001136004557001136027691001
3018490316001017053072001017060663001017067792001
4017023735001017052845001017070806001017161670001
5018619171001018617358001017060659001017060246001
6018619165001017052885001017044247001
7017068487001136028205001018040312001
8017053056001017060667001
9018210505001
After
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Actually I tested this script and works only if I know exactly how many pallets. How can I make this work regardless of the number of pallets?

Code:
Sub PalletSorter()
    Dim i As String
    Range("A1").Select
    x = 1
    Do Until x = 13
        i = ActiveCell.Value
        i = i + 1
        Cells.Find(What:=i, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.Cut
        Cells(Selection.Row, Columns.Count).End(xlToLeft).Offset(, 1).Select
        Selection.End(xlUp).Select
        ActiveSheet.Paste
        Selection.End(xlUp).Select
        x = x + 1
       Loop
    
End Sub
 
Upvote 0
See how this works. Select (highlight) the cells and run it.

Code:
Option Explicit
Sub PalletSorter()
    
    Dim rUsing As Range, rPallet As Range, rPriorPallet As Range
    Dim sNextPallet As String
    Dim ct As Long
    
    Set rUsing = Selection
    
    If rUsing.Columns.Count > 1 Or rUsing.Cells.Count < 2 Or rUsing.Areas.Count > 1 Then
        MsgBox "This macro requires: the selection of multiple and contiguous cells that are all within a single column.  Now exiting."
        Exit Sub
    End If
    
    Set rPallet = rUsing.Cells(1)
    
    ct = 0
    Do While Not rPallet Is Nothing
        
        sNextPallet = Application.WorksheetFunction.Rept("0", Len(rUsing.Cells(1).Value) - Len(rPallet.Value + 1)) & rPallet.Value + 1
        Set rPriorPallet = rPallet
        Set rPallet = rUsing.Cells.Find(What:=sNextPallet, After:=rPallet, SearchDirection:=xlNext)

        ct = ct + 1
        
        If Not rPallet Is Nothing Then
            Range(rPriorPallet, rPallet.Offset(-1)).Copy Destination:=rUsing.Cells(1).Offset(, ct + 3)
        Else
            Range(rPriorPallet, rUsing.Cells(rUsing.Cells.Count)).Copy Destination:=rUsing.Cells(1).Offset(, ct + 3)
        End If
    Loop
    
    Range(rUsing.Cells(1).Offset(, 3), rUsing.Cells(1).Offset(, 3 + ct)).Font.Bold = True
End Sub
 
Upvote 0
Thanks gregtx81 for your help

When I run the script, I get this message: This macro requires: the selection of multiple and contiguous cells that are all within a single column. Now exiting.
 
Upvote 0
You've got to select (highlight) the cells you want the macro to run on... they don't have to start in A1.


If you have a lot of cells, activate the first one(click it or use keyboard arrows), then hold ctrl+shift and press the down arrow to select all of them.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top