Consulting

Results 1 to 11 of 11

Thread: BOM Challenge

  1. #1

    BOM Challenge

    Hello
    I have a challenge that a can't solve.
    i have a BOM with many level (the levels shown in column 'A')
    i need to calculate the sum prices of each level to its upper level (the final result is shown in column 'D') and each part price is shown in column 'C'.
    for example :
    line 19 should be the sum of : line 20 + line 19
    line 15 should be the sum of : line 16 + line 15


    line 8 should be the sum of : line 19 + line 18 +line 17 + line 15 +line 14 + line 13 +line 9 (all the levels below, in this case level 3)


    until now, i haven't found a solution, please help...


    thank you
    Attached Files Attached Files

  2. #2
    i messed this up so removed for the time being
    Last edited by westconn1; 08-17-2014 at 02:56 AM.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I'm confused. You say that 'line 8 should be the sum of : line 19 + line 18 +line 17 + line 15 +line 14 + line 13 +line 9', which in your workbook shows a value of 229.19. But if I add those lines I get 208.82. If I add up all of the values for 3,4,5 below line 8, then I get 229.19. SO which is it meant to be?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Contributor
    Joined
    Jul 2004
    Location
    Gurgaon, India
    Posts
    148
    Location
    In D2 and copied down,

    =IF(A2=1,SUM($C$2:$C$20),SUMPRODUCT(--(--(SUBSTITUTE(A2:INDEX(A2:$A$20,IFERROR(MATCH(SUBSTITUTE(A2,".",""),INDEX(SUB STITUTE(A3:$A$20,".",""),0,0),0),COUNTA(A2:$A$20))),".",""))>=--SUBSTITUTE(A2,".","")),C2:INDEX(C2:$C$20,IFERROR(MATCH(SUBSTITUTE(A2,".","" ),INDEX(SUBSTITUTE(A3:$A$20,".",""),0,0),0),COUNTA(A2:$A$20)))))
    ________________
    Kris

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Is that a launch code for something?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    i can follow most of it, but iferror does not appear to work for my version of excel

  7. #7
    VBAX Contributor
    Joined
    Jul 2004
    Location
    Gurgaon, India
    Posts
    148
    Location
    PHP Code:
    =IF(A2=1,SUM($C$2:$C$20),SUMPRODUCT(--(--(SUBSTITUTE(A2:INDEX(A2:$A$20,IF(ISERROR(MATCH(SUBSTITUTE(A2,".",""),INDEX(SUBSTITUTE(A3:$A$20,".",""),0,0),0)),COUNTA(A2:$A$20),MATCH(SUBSTITUTE(A2,".",""),INDEX(SUBSTITUTE(A3:$A$20,".",""),0,0),0))),".",""))>=--SUBSTITUTE(A2,".","")),C2:INDEX(C2:$C$20,IF(ISERROR(MATCH(SUBSTITUTE(A2,".",""),INDEX(SUBSTITUTE(A3:$A$20,".",""),0,0),0)),COUNTA(A2:$A$20),MATCH(SUBSTITUTE(A2,".",""),INDEX(SUBSTITUTE(A3:$A$20,".",""),0,0),0))))) 
    ________________
    Kris

  8. #8
    should substitute work on an array?

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Little on the brute force side, but should a starting point


    Option Explicit
    Sub BOM_Cost()
        Dim aBOM As Variant
        Dim iLevel As Long, iMaxLevel As Long, iRow As Long, iRow2 As Long, iNumRows As Long
     
        'load array with data
        aBOM = Cells(1, 1).CurrentRegion.Value
        
        iNumRows = UBound(aBOM, 1)
    
        'remove dots, convert level to long, make total = unit
        'determine highest level
        For iLevel = 2 To iNumRows
            aBOM(iLevel, 1) = Replace(aBOM(iLevel, 1), ".", vbNullString)
            aBOM(iLevel, 1) = CLng(aBOM(iLevel, 1))
            aBOM(iLevel, 4) = aBOM(iLevel, 3)
            
            If aBOM(iLevel, 1) > iMaxLevel Then iMaxLevel = aBOM(iLevel, 1)
        
        Next iLevel
        For iLevel = iMaxLevel To 1 Step -1
        
            For iRow = 2 To iNumRows - 1
                
                If aBOM(iRow, 1) = iLevel Then
                                    
                    For iRow2 = iRow + 1 To iNumRows
                        If aBOM(iRow2, 1) = iLevel + 1 Then
                            aBOM(iRow, 4) = aBOM(iRow, 4) + aBOM(iRow2, 4)
                                            
                        ElseIf aBOM(iRow2, 1) = iLevel Then
                            Exit For
                        End If
                    Next iRow2
                End If
        
            Next iRow
        
        Next iLevel
    
        'test
        Cells(1, 12).ClearContents
        Cells(1, 12).Resize(UBound(aBOM, 1), UBound(aBOM, 2)).Value = aBOM
    End Sub
    Attached Files Attached Files
    Last edited by Paul_Hossler; 08-19-2014 at 07:19 AM. Reason: Left a 'test line in
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  10. #10
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Formula in #7 by Krishna Kumar seems to be working fine.

    And here's one challenge cooking up on it on Chandoo
    http://chandoo.org/forum/threads/for...y-level.18447/
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  11. #11
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    For myself, I find extremely long and complex formulas with lots of nested parens, IF's, other worksheet formulas very hard to construct and even harder to maintain

    When the data is no longer in A1 : C20 I would find changing the references in the #7 formula to the new ones more trouble than it's worth

    I think the 20 rows are just an example, and that the actually number of rows will vary. So I would consider a more flexible solution that doesn't depend on explicit addresses embedded in formulas

    But that's just my opinion

    Not saying that my suggested VBA is perfect (since there was only a single data set to use for testing), but it could be a prototype algorithm for a more robust solution
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •