+ Reply to Thread
Results 1 to 3 of 3

Help to calculate "Bill of Material" for products in nested layers...

Hybrid View

  1. #1
    Registered User
    Join Date
    09-22-2022
    Location
    Sweden
    MS-Off Ver
    MS Office Plus 2021
    Posts
    1

    Help to calculate "Bill of Material" for products in nested layers...

    Hi !

    Got a really tricky logic to crack.

    Keeping it short: I need to calculate how much rawmaterial that is required to produce a product. In this exmaple the E product.
    However, The E Product is not composed of only rawmaterials (would be easy to sum up) but is composed of other refined products that is composed of other refined products that all have a mix of the rawmaterials.

    Please see attached excel.
    This kind of nested "Bill of Material" of products makes it difficult to calculate the core rawmaterial required.
    I have tried to make it easy in the excel for the example.

    There is a:
    - Conversion table ----- SEE S6
    - An input Table of what I want to produce ----- SEE B10
    - and the Output (result) table ----- SEE I10 where all of this should calculate how many "rawmaterials" required.

    How can this be solved with formulas or perhaps a data model ?

    see attached example excel:


    Much appreciate this support and tough nut to crack.

    Production tables.xlsx
    Last edited by CJVE; 09-22-2022 at 03:40 AM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,366

    Re: Help to calculate "Bill of Material" for products in nested layers...

    In concept it is (or appears to be) very similar to this ..

    https://www.excelforum.com/excel-for...-bom-cost.html

    how many variants are there of the Realtion table i.e how many finished products / how many material products (given the latter can include the former) ?
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,366

    Re: Help to calculate "Bill of Material" for products in nested layers...

    Give this a try: my results differ from yours: see sheet1 for my interpretation of the logic.

    Sub Get_Materialsx()
    Dim pAr, rAr, rpAr, wkAr, rTabl, ipar
    
    pAr = Range("Products")
    rAr = Range("Raw_Materials")
    rpAr = Range("Refined_Product")
    opar = Range("Output_Products")
    ipar = Range("Input_Products")
    rtbl = Range("Relation_Tbl")
    
    ReDim wkAr(1 To UBound(rAr))
    
    For i = 1 To UBound(rAr, 1)
        wkAr(i) = 0
    Next i
    
    i = Application.Match(rpAr(1, 1), opar, 0)  ' Position of start of "Defined Product" in "Relation Table"
    Debug.Print "ptr", "i", "Key", "mv", "mtype", "wkAr(1)", "wkAr(2)", "j", "rtbl(j, 3)"
    If Not IsError(i) Then
        j = 0
        Do While opar(i, 1) = rpAr(1, 1) ' Loop for all occurences of Defined Product
            j = j + 1
            Key = rtbl(i, 2)
            mv = rtbl(i, 3)
    
            j = Application.Match(Key, rAr, 0) ' Is this a raw material ?
            If Not IsError(j) Then
               mtype = "RM"
               mv = 1
               Else
                   j = Application.Match(Key, opar, 0) ' Is this a raw material ?
                   If Not IsError(j) Then
                      mtype = "RT"
                      Key = rtbl(j, 1)
                   End If
            End If
            
            'ptr = "(1)"
           ' Debug.Print ptr, i, Key, mv, mtype, wkAr(1), wkAr(2)
            
            Select Case mtype
            
            Case Is = "RM"  ' Raw material
                
                For k = 1 To UBound(rAr, 1)
                    If Key = rAr(k, 1) Then
                      wkAr(k) = wkAr(k) + rtbl(j, 3) * mv
                      Exit For
                    End If
                Next k
             'ptr = "(2)"
            ' Debug.Print ptr, i, Key, mv, mtype, wkAr(1), wkAr(2), j, rtbl(j, 3)
            Case Is = "RT"  '
            
    Do_again:
                Do While rtbl(j, 1) = Key
                
                    For k = 1 To UBound(rAr, 1)
                        If rtbl(j, 2) = rAr(k, 1) Then
                          wkAr(k) = wkAr(k) + rtbl(j, 3) * mv
                          j = j + 1
                          GoTo loop_Again
                        End If
                    Next k
                   ' ptr = "(3)"
                   ' Debug.Print ptr, i, Key, mv, mtype, wkAr(1), wkAr(2), j, rtbl(j, 3)
                     'mType = "RT"
                     Key = rtbl(j, 2)
                     j = Application.Match(Key, ipar, 0) ' Is this a raw material ?
                     If Not IsError(j) Then
                     ' mType = "RT"
                      mv = mv * rtbl(j, 3)
                      Key = rtbl(j, 2)
                      j = Application.Match(Key, opar, 0) ' Is this a raw material ?
                    End If
                   ' ptr = "(4)"
                   ' Debug.Print ptr, i, Key, mv, mtype, wkAr(1), wkAr(2), j, rtbl(j, 3)
                    GoTo Do_again
                    
    loop_Again:
               Loop
                   
                   
    exit_Select:
            End Select
            
            i = i + 1
            If i > UBound(rtbl, 1) Then Exit Do
        Loop
        
    End If
    
    [A37] = wkAr(1) * Range("Refined_Product")(1, 2)
    [a38] = wkAr(2) * Range("Refined_Product")(1, 2)
    End Sub
    I have used named ranges so if this works then you need to provide a sample of how your real data is formatted.
    Attached Files Attached Files

+ 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. [SOLVED] Calculate Material Release - Bill of Material
    By mgoh in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-17-2021, 06:40 AM
  2. Replies: 11
    Last Post: 09-24-2017, 11:53 AM
  3. [SOLVED] Nested HLOOKUP returns "FALSE" in cell where result should be "0.00"
    By gammccubbin in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-09-2016, 09:49 AM
  4. Macro for "Master" and "Child" products with image files
    By ddenicola in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2014, 08:30 AM
  5. Replies: 1
    Last Post: 01-15-2014, 08:53 AM
  6. Replies: 6
    Last Post: 01-20-2010, 09:07 AM
  7. Replies: 13
    Last Post: 06-08-2008, 12:48 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