+ Reply to Thread
Results 1 to 9 of 9

List all Permutations of two lists

  1. #1
    Registered User
    Join Date
    03-21-2013
    Location
    Auckland New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    6

    Smile List all Permutations of two lists

    Greetings. Can someone please help me with this. I have been struggling without making much progress

    I want to create a list of all Customers Products and Prices on Sheet 1 from a list of Customers and a list of Products.
    The Customers list is on Sheet2 and the Product List is on Sheet3, (or both could be on Sheets 2 if easier)

    For example, the Customers could be John and Bill, and the Products List could be
    A B C
    Product Quantity Price
    Widget 1 10.00
    Widget 10 9.00
    Gizmo 1 2.00

    The result on Sheet1 would be
    A B C D
    Customer Product Quantity Price
    John Widget 1 10.00
    John Widget 10 9.00
    John Gizmo 1 2.00
    Bill Widget 1 10.00
    Bill Widget 10 9.00
    Bill Gizmo 1 2.00

    Thank you - Anthony

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: List all Permutations of two lists

    There's a workbook that will do this with two methods, one using formulas and one with VBA, at https://www.box.com/s/47b28f19d794b25511be. You'll need to use a separate lookup formula to get the product quantity and cost.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    03-21-2013
    Location
    Auckland New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: List all Permutations of two lists

    Thanks - have checked that out and it is pretty close.
    The macro version would probably suit me best, as then the user does not need to copy any formuales.
    Unfortunatly my understanding is not sufficient - I have tried to modify it to meet my requirements but I am currently lost :o)

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: List all Permutations of two lists

    Sorry, I have no idea how to respond to that.
    Last edited by shg; 03-22-2013 at 12:46 AM.

  5. #5
    Registered User
    Join Date
    03-21-2013
    Location
    Auckland New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: List all Permutations of two lists

    I think I need a bit of code that does the following but dont know the syntax - can you help me with that?
    (Assuming Sheet2 Columns A=Customers, B=Products, C=Quantity, D=Price)

    CustomerCount = Rows in Column A
    ProductCount = Rows in Column B
    row = 1
    For C = 1 to CustomerCount
    For P = 1 to ProductCount
    Sheet1!Cell("A" & row) = Cell("A" & C)
    Sheet1!Cell("B" & row) = Cell("B" & P)
    Sheet1!Cell("C" & row) = Cell("C" & P)
    Sheet1!Cell("D" & row) = Cell("D" & P)
    row = row + 1
    Next P
    Next C

    Thanks Anthony

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: List all Permutations of two lists

    If you can upload an example of your workbook with the expected results Im sure someone could help you.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  7. #7
    Registered User
    Join Date
    03-21-2013
    Location
    Auckland New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: List all Permutations of two lists

    Example attached - with two Customers and three Products - in reality there would be many more.
    The data would be entered on the Customer and Product tabs, and the output required is on Sheet1 (the Import tab)
    Saved as .xls for loading here but .xlsm would be fine.

    Thanks Anthony
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-21-2013
    Location
    Auckland New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: List all Permutations of two lists

    In my attached example, I put the Customers List and the Products list on different sheets, to highlight the fact that they are two separate lists. In practise I could put them as separate columns on the same sheet, if that makes it easier.

  9. #9
    Registered User
    Join Date
    03-21-2013
    Location
    Auckland New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    6

    Smile Resolved - List all Permutations of two lists

    Eventually Managed to Resolve it myself thanks.

    I opted to have my Customerlist on Sheet2, my Productlist on Sheet3, and generate my data on Sheet1 via the following

    Option Explicit
    Sub Process()
    Dim CustomerRow As Long
    Dim ProductRow As Long
    Dim OutputRow As Long
    Sheet1.Cells.Clear 'Get rid of any previous values
    OutputRow = 1
    Sheet1.Cells(OutputRow, "A") = "Customer"
    Sheet1.Cells(OutputRow, "B") = "Product"
    Sheet1.Cells(OutputRow, "C") = "Quantity"
    Sheet1.Cells(OutputRow, "D") = "Price"
    CustomerRow = 2 ' Allow for Headings in Row 1
    Do Until Sheet2.Cells(CustomerRow, "A") = ""
    ProductRow = 2 ' Allow for Headings in Row 1
    Do Until Sheet3.Cells(ProductRow, "B") = ""
    OutputRow = OutputRow + 1
    Sheet1.Cells(OutputRow, "A") = Sheet2.Cells(CustomerRow, "A")
    Sheet1.Cells(OutputRow, "B") = Sheet3.Cells(ProductRow, "A")
    Sheet1.Cells(OutputRow, "C") = Sheet3.Cells(ProductRow, "B")
    Sheet1.Cells(OutputRow, "D") = Sheet3.Cells(ProductRow, "C")
    ProductRow = ProductRow + 1
    Loop
    CustomerRow = CustomerRow + 1
    Loop
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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