Convert single PO line item to multiple rows based on quantity ordered

MattsDad

New Member
Joined
Sep 1, 2010
Messages
14
Hi. I'm trying to build a process to aid our warehouse in printing barcode labels for inventory received. Currently someone has to take the PO/receiving document and manually enter the part number into a text file on a separate row for each individual piece that is received so our barcode printer can print the correct label to attach to our product.

For example, on a basic receiving document we receive 3 units of Item A and 1 unit of Item B that shows like this:
Item Qty
A 3
B 1

The warehouse worker then enters the data like this in the text file that will be printed:
A
A
A
B

The question is, can i do this in Excel 2003 on an XP box? We can easily import this data from the PO/receiving report to Excel, which I have done. I'm trying to figure out how to get Excel to create an output file either directly to a text file or to another tab in the workbook but I don't know how to instruct Excel to use one line of input as a source for more than one line of output.

I've spent several hours trying formulas to no avail. I don't know enough about VBA code to be able to write this myself. Any help you can give will be greatly appreciated.
 
Welcome to the MrExcel board!

I'm not really sure what you are asking.

BTW, best not to fully quote long posts as it makes the thread harder to read/navigate. If you want to quote, just quote small, relevant parts only.

thanks peter for your quick answer i just need to know how i can make this VBA code live on excel 2016 as mentioned above and sorry for long quote :)
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
thanks peter for your quick answer i just need to know how i can make this VBA code live on excel 2016 ..
The code works for me on Excel 2016 as it is. What problems are you having?
Have you tried it on a fresh sheet with the sample data as shown in columns A:D of post 6? Does it work for you for that data?
 
Upvote 0
its worked but im trying to make it on my data so can i give you it and make it for me please ?
 
Upvote 0
its worked but im trying to make it on my data so can i give you it and make it for me please ?
You are welcome to post a small set of your dummy data and expected results so we can see what you have and what you are trying to achieve. My signature block below has a link for how to do that.
 
Upvote 0
You are welcome to post a small set of your dummy data and expected results so we can see what you have and what you are trying to achieve. My signature block below has a link for how to do that.

thanks peter so my orders is,

[TABLE="width: 692"]
<tbody>[TR]
[TD="align: center"]ORDER_NUMBER[/TD]
[TD="align: center"]SKU[/TD]
[TD="align: center"]DESCRIPTION[/TD]
[TD="align: center"]ORDERED_QUANTITY[/TD]
[TD="align: center"]DELIVERY_METHOD[/TD]
[/TR]
[TR]
[TD="align: center"]5004811[/TD]
[TD="align: center"]112170313[/TD]
[TD="align: center"]iPhone 7 32GB Matte Black Local[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]MovEx[/TD]
[/TR]
[TR]
[TD="align: center"]5004828[/TD]
[TD="align: center"]112170379[/TD]
[TD="align: center"]IPhone 6 32GB Grey LTE/ Local[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]ELT Driver[/TD]
[/TR]
[TR]
[TD="align: center"]5004845[/TD]
[TD="align: center"]112170387[/TD]
[TD="align: center"]iPhone 8 Plus 64GB Space Grey /Local[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Sales[/TD]
[/TR]
[TR]
[TD="align: center"]5004714[/TD]
[TD="align: center"]112170402[/TD]
[TD="align: center"]Iphone X 256 GB Silver /Local[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]NokSmart[/TD]
[/TR]
[TR]
[TD="align: center"]5004710[/TD]
[TD="align: center"]112170404[/TD]
[TD="align: center"]IPhone X 256 GB Space Gray/Local[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Union Courier[/TD]
[/TR]
</tbody>[/TABLE]

i need to distributed into that example,

[TABLE="width: 910"]
<tbody>[TR]
[TD]Order[/TD]
[TD]SKU[/TD]
[TD]Item Description[/TD]
[TD]QTY[/TD]
[TD]Serial Numbers[/TD]
[TD]18 Digit[/TD]
[TD]SR Number[/TD]
[TD]Released By[/TD]
[TD]Delivery Method[/TD]
[TD]Order Status[/TD]
[/TR]
[TR]
[TD]5004811[/TD]
[TD]112170313[/TD]
[TD]iPhone 7 32GB Matte Black Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]MovEx[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]112170313[/TD]
[TD]iPhone 7 32GB Matte Black Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]MovEx[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5004828[/TD]
[TD]112170379[/TD]
[TD]IPhone 6 32GB Grey LTE/ Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]ELT Driver[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]112170379[/TD]
[TD]IPhone 6 32GB Grey LTE/ Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]ELT Driver[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5004845[/TD]
[TD]112170387[/TD]
[TD]iPhone 8 Plus 64GB Space Grey /Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Sales[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]112170387[/TD]
[TD]iPhone 8 Plus 64GB Space Grey /Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Sales[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5004714[/TD]
[TD]112170402[/TD]
[TD]Iphone X 256 GB Silver /Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]NokSmart[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]112170402[/TD]
[TD]Iphone X 256 GB Silver /Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]NokSmart[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5004710[/TD]
[TD]112170404[/TD]
[TD]IPhone X 256 GB Space Gray/Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Union Courier[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]112170404[/TD]
[TD]IPhone X 256 GB Space Gray/Local[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Union Courier[/TD]
[TD="align: center"][/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 898"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Welcome to the MrExcel board!

My best guess, without seeing a small set of sample data and expected results is as follows.
Test in a copy of your workbook.

If it is not what you want, please give a small set of sample data and expected results together with further explanation. My signature block below has further info about how to do screen shots.

Rich (BB code):
Sub Rearrange()
  Dim a, b
  Dim i As Long, j As Long, k As Long, z As Long
  
  With Range("A2", Range("D" & Rows.Count).End(xlUp))
    a = .Value
    ReDim b(1 To 4, 0 To 0)
    For i = 1 To UBound(a)
      ReDim Preserve b(1 To 4, 1 To UBound(b, 2) + a(i, 4))
      For j = 1 To a(i, 4)
        z = z + 1
        For k = 1 To 4
          b(k, z) = a(i, k)
        Next k
      Next j
    Next i
    .Offset(, .Columns.Count + 1).Resize(z).Value = Application.Transpose(b)
  End With
End Sub


around this code please can you tell me how can i make this Red Function?
thank you
 
Last edited by a moderator:
Upvote 0
Try this code in a copy of your workbook.
Code:
Sub Rearrange()
  Dim a, b
  Dim i As Long, j As Long, k As Long, z As Long, rws As Long, cols As Long
  
  With Range("A2", Range("E" & Rows.Count).End(xlUp))
    a = .Value
    rws = Application.WorksheetFunction.Sum(.Columns(4))
    cols = UBound(a, 2)
    ReDim b(1 To rws, 1 To cols)
    For i = 1 To UBound(a)
      For k = 1 To a(i, 4)
        z = z + 1
        For j = 1 To cols
            b(z, j) = a(i, j)
        Next j
      Next k
    Next i
    With .Offset(, .Columns.Count + 1).Resize(rws)
      .Value = b
      .Columns(5).Resize(, 4).Insert
      .Cells(0, 1).Resize(, 10).Value = Split("Order|SKU|Item Description|QTY|Serial Numbers|18 Digit|SR Number|Released By|Delivery Method|Order Status", "|")
      .Columns(4).Value = 1
      .CurrentRegion.Columns.AutoFit
    End With
  End With
End Sub
 
Upvote 0
How can i post it on my workbook ? i put it as a module 1 or what ?
 
Upvote 0
How can i post it on my workbook ? i put it as a module 1 or what ?
Hmm, in post 13 you said the previous code "worked" so I assumed you knew how to implement the code. :)

To implement ..
1. With your workbook active press Alt+F11 to bring up the vba window.
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Press Alt+F8 to bring up the Macro dialog
6. Select the macro & click ‘Run’
7. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)
 
Upvote 0
many thanks for your usual support peter you're really polite man and im sorry for disturbing you many times so ive another question can i do this functions with macro codes ? for example with offset function with any formulas ? :)
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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