+ Reply to Thread
Results 1 to 3 of 3

Itemize Product based on quantity into Multiple Rows

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    2

    Itemize Product based on quantity into Multiple Rows

    Hi,

    I need help with itemizing each product into a separate row based on the quantity:

    Example:

    This is currently what I have:

    [Product][Quantity]
    [CRT00000][3]
    [CRT00001][2]

    This is what I need:

    [CRT00000][1]
    [CRT00000][1]
    [CRT00000][1]
    [CRT00001][1]
    [CRT00001][1]

    Does anyone know how I can make this happen?

    Thank you very much in advance.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Itemize Product based on quantity into Multiple Rows

    Hi

    Macro perhaps

    Sub aaa()
      Range("D1:E1").Value = Range("A1:B1").Value
      For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
        For j = 1 To Cells(i, 2)
          outrow = Cells(Rows.Count, "D").End(xlUp).Offset(1, 0).Row
          Cells(outrow, 4).Value = Cells(i, 1).Value
          Cells(outrow, 5).Value = 1
        Next j
      Next i
    End Sub
    rylo

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Itemize Product based on quantity into Multiple Rows

    sostenes,

    I assume that cell A1 contains Product and cell B1 contains Quantity.


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


    
    Option Explicit
    Sub ReorgData()
    ' stanleydgromjr, 12/05/2012
    ' http://www.excelforum.com/excel-general/881780-itemize-product-based-on-quantity-into-multiple-rows.html
    Dim r As Long, lr As Long
    Application.ScreenUpdating = False
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    For r = lr To 2 Step -1
      If Cells(r, 2).Value > 1 Then
        Rows(r + 1).Resize(Cells(r, 2).Value - 1).Insert
        Cells(r + 1, 1).Resize(Cells(r, 2).Value - 1) = Cells(r, 1).Value
        Cells(r, 2).Resize(Cells(r, 2).Value) = 1
      End If
    Next r
    Application.ScreenUpdating = True
    End Sub

    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


    Then run the ReorgData macro.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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