Multi-level Bill Of Materials explosion

Andy Howcroft

New Member
Joined
Oct 3, 2023
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a single level Bill Of Materials (BOM) report that shows all parent assemblies with their subsequent child parts. I need to create a complete record of multi-level BOMs for all our products with the BOM level shown for each assembly/part.

Please note:
  • The child part can also be an assembly and therefore appears in the ‘Parent’ column.
  • The child parts/assemblies can be used in multiple assemblies.
  • The BOM level can be 20+.
  • We have 2,500 products and 10,000+ parts/assemblies and so the resulting report will be rather large.

Current report showing two Products and all subsequent assemblies and parts:
1696556172291.png



Required multi-level report with BOM levels shown for each assembly/part:
1696556200850.png


I am led to believe this could be achieved with either VBA or Power Pivot, but any other method will of course be appreciated.

Many thanks in advance.
 
Here a recursive VBA approach. Paste this code in a new module. I used below dataset to test.
Paste the data in A1 first.

VBA Code:
Dim j As Long, aData, xp, aBom

Sub jec()
 Dim it As Variant
 j = 0
 aData = Sheets("Data").Cells(1).CurrentRegion
 Set dic = CreateObject("scripting.dictionary")
 For t = 2 To UBound(aData)
    dic(aData(t, 1)) = Empty
 Next
 ReDim aBom(1 To 50000, 1 To 9)
 For Each it In dic.keys
    xp = it
    GetBom it, 1
 Next
 Sheets("Data").Range("m1").Resize(, 9) = Array("Lvl", "Item", "Seq", "Stepname", "LineNr", "CodeType", "Description", "Unit", "Qty")
 Sheets("Data").Range("m2").Resize(UBound(aBom), 9) = aBom
End Sub

Private Sub GetBom(sPart As Variant, iLvl As Integer)
 Dim i As Long, c As Long
 For i = 2 To UBound(aData)
    If aData(i, 1) = sPart Then
      j = j + 1
      If aData(i, 1) = xp Then
        aBom(j, 1) = iLvl
        aBom(j, 2) = xp
        aBom(j + 1, 1) = iLvl + 1
        aBom(j + 1, 2) = Space(iLvl * 10) & aData(i, 6)
        j = j + 1
        xp = ""
      Else
        aBom(j, 2) = Space(iLvl * 10) & aData(i, 6)
        aBom(j, 1) = iLvl + 1
      End If
      For c = 2 To 8
        aBom(j, c + 1) = aData(i, IIf(c > 5, c + 1, c))
      Next
        GetBom aData(i, 6), iLvl + 1
    End If
 Next
End Sub



ITEMCODESTEPSEQUENCESTEPNAMELINENUMBERCODETYPELINECODELINEDESCRIPTIONLINEUNITPERQTY
CLM0022SBA-SM
900​
Assembly
85​
Item CodeCLM0337CB255mm Pitch Footing Channel AssemblyEach
1​
CLM0022SBA-SM
190​
PACK LIST
20​
Item CodeFST013NUT NYLOC M10 Zinc (2000 QTY)Each
4​
CLM0022SBA-SM
900​
Assembly
40​
Item CodePNL1688SBAPS Hand Grip Assy (Pair) (AS4685:2021)Each
1​
CLM0022SBA-SM
190​
PACK LIST
10​
Item CodeCAP0023CM-BLACKNUT COVER & CAP PLASTIC - 10MM - BlackEach
4​
CLM0022SBA-SM
900​
Assembly
90​
Item CodeSHT0738CBCPfm Support Plate 5mm SS - for Cable Rope Climbers PcoatedEach
1​
CLM0022SBA-SM
190​
PACK LIST
90​
Labour CodePACKINGPackingMinutes
20​
CLM0022SBA-SM
190​
PACK LIST
50​
Item CodeFST2000M14 Square Washer Galv - 50x50x3.0Each
2​
CLM0022SBA-SM
190​
PACK LIST
30​
Item CodeFST142Excalibur Screwbolt 12 x 100 DSA 12-100-G Incl. Gal Washer (Dome Head)Each
2​
CLM0022SBA-SM
200​
DISPATCH ASSY
90​
Labour CodeDISPATCH ASSYAssemble as per PicklistMinutes
30​
CLM0022SBA-SM
190​
PACK LIST
25​
Item CodeFST0034CMWASHER FLAT S/S 3/8 X 3/4 X 18" (5000 QTY)Each
4​
CLM0022SBA-SM
900​
Assembly
80​
Item CodeROP0389CBCable Rope for Climber Net 1200 - Chain FootingEach
1​
CLM0337CB
120​
DISPATCH ASSY
40​
Item CodeFST2001M10 Large Washer S/S 304 - Ø30ODEach
4​
CLM0337CB
120​
DISPATCH ASSY
10​
Item CodeCLM0337CM255mm Pitch Footing ChannelEach
1​
CLM0337CB
120​
DISPATCH ASSY
20​
Item CodeKRP5040Chain Boss Flat Surface M10 316 SSEach
4​
CLM0337CB
120​
DISPATCH ASSY
30​
Item CodeFST0320SCREW BUTTON TORX S/S M8 X 25 (QTY1000)Each
4​
CLM0337CB
120​
DISPATCH ASSY
50​
Item CodeFST0002CMSCREW BUTTON TORX S/S M10 X 16 (TW 111051) (800 QTY)Each
4​
CLM0337CB
120​
DISPATCH ASSY
60​
Labour CodeDISPATCH ASSYAssemble as per PicklistMinutes
10​
CLM0337CM
910​
FABRICATION
20​
Labour CodeFABRICATION ASSYAssembly FabricationMinutes
10​
CLM0337CM
910​
FABRICATION
50​
Item CodeCLM0331CMUniversal Footing Channel Type 1Each
1​
CST1001SB
20​
EXT MACHINE
30​
Labour CodeHANDLINGHandlingMinutes
1​
CST1001SB
20​
EXT MACHINE
40​
Item CodeCST0001SMPS 27 Single Hole Flange (Flat)(AP-005)Each
1​
CST1001SB
20​
EXT MACHINE
50​
Descriptor CodeCST1001SEMachine CST0001SM PS 27 Single Hole Flange (Flat)Each
1​
FST0001CB
10​
PACK LIST
10​
Item CodeFST0005CMSCREW BUTTON TORX S/S M10 X 40 (TW - 18999) (2000 QTY)Each
1​
FST0001CB
190​
DISPATCH ASSY
20​
Item CodeFST009NUTSERT M10 SPLINED ZP (TW-17893) - Grip Range .78mm to 3.8mmEach
1​
FST0001CB
190​
DISPATCH ASSY
30​
Labour CodeUPRIGHT ASSYNutsert and Cap FitmentMinutes0.5
FST0001CB
10​
PACK LIST
60​
Labour CodePACKINGPackingMinutes0.5
FST0001CB
20​
CUT LIST
70​
Labour CodeCUT AND DRILLCut and Drill MetalMinutes
1​
FST0223-L25
130​
FABRICATION
10​
Item CodeFST0223CMAllthread M10 x 1000 SS 316Each0.03
FST0223-L25
130​
FABRICATION
20​
Labour CodeFABRICATION ASSYAssembly FabricationMinutes
5​
PNL0686SB
100​
FABRICATION
10​
Item CodePBN0395CM27 OD Hand Grip Inner Bend (AS4685:2021)Each
1​
PNL0686SB
100​
FABRICATION
20​
Item CodeFST0009CMSCREW BUTTON TORX S/S M8 X 20Each
1​
PNL0686SB
100​
FABRICATION
30​
Item CodeCST0001SMPS 27 Single Hole Flange (Flat)(AP-005)Each
1​
PNL0686SB
100​
FABRICATION
50​
Labour CodeFABRICATION ASSYFabricated AssemblyMinutes
15​
PNL0686SBC
20​
POWDERCOAT
10​
Item CodePNL0686SBPS Hand Grip Inner (AS4685:2021)Each
1​
PNL0686SBC
20​
POWDERCOAT
20​
Labour CodePOWDERCOATPowder Coating OperationMinutes
4​
PNL0687SB
100​
FABRICATION
60​
Item CodeFST0009CMSCREW BUTTON TORX S/S M8 X 20Each
2​
PNL0687SB
100​
FABRICATION
10​
Item CodePBN0396CM27 OD Hand Grip Outer Bend (AS4685:2021)Each
1​
PNL0687SB
100​
FABRICATION
30​
Item CodeCST1001SBPS 27 Single Hole Flange (Flat) Machined for 3 screwsEach
1​
PNL0687SB
100​
FABRICATION
50​
Labour CodeFABRICATION ASSYFabricated AssemblyMinutes
15​
PNL0687SB
100​
FABRICATION
70​
Item CodeFST165M8 X 16 RTOX (1000 QTY)Each
1​
PNL0687SBC
20​
POWDERCOAT
10​
Item CodePNL0687SBPS Hand Grip Outer (AS4685:2021)Each
1​
PNL0687SBC
20​
POWDERCOAT
20​
Labour CodePOWDERCOATPowder Coating OperationMinutes
6​
PNL1688SBA
900​
Assembly
10​
Item CodePNL0686SBCPS Hand Grip Inner (AS4685:2021) PcoatedEach
2​
PNL1688SBA
190​
PACK LIST
20​
Item CodeFST0034CMWASHER FLAT S/S 3/8 X 3/4 X 18" (5000 QTY)Each
4​
PNL1688SBA
900​
Assembly
50​
Item CodeFST0001CBPR/PS Nutsert M10 x 40 AssyEach
4​
PNL1688SBA
190​
PACK LIST
60​
Item CodeFST0004CMSCREW BUTTON TORX S/S M10 X 25 (800 QTY)Each
4​
PNL1688SBA
190​
PACK LIST
30​
Labour CodePACKINGPackingMinutes
15​
PNL1688SBA
900​
Assembly
70​
Item CodeFST0019CMTube Closure - Plastic 27 x M10 (N782110MMB)Each
4​
PNL1688SBA
900​
Assembly
80​
Item CodePNL0687SBCPS Hand Grip Outer (AS4685:2021) PcoatedEach
2​
ROP0389CB
70​
ROPE LIST
140​
Item CodeCHN0100CMChain 6mm Short Link ST/STEELM2.4
ROP0389CB
70​
ROPE LIST
10​
Item CodeROP0012CMCross Joint Ferrule (GC16-C)Each
6​
ROP0389CB
70​
ROPE LIST
20​
Item CodeROP0014CMShort Eye Ferrule (GC16-EK - 24mm)Each
4​
ROP0389CB
70​
ROPE LIST
30​
Item CodeROP0018CMShort T-Cross Joint Ferrule (GC16-TCK)Each
6​
ROP0389CB
70​
ROPE LIST
50​
Item CodeFST0219CM10G x 2" Csunk Square Drive Quad Screw SSEach
12​
ROP0389CB
70​
ROPE LIST
60​
Item CodeROP0001CM-BLACKCombi Rope 16 (GC16-RMU) (Black)M7.3
ROP0389CB
70​
ROPE LIST
150​
Labour CodeROPERope AssemblyMinutes
115​
ROP0389CB
70​
ROPE LIST
80​
Item CodeROP0022CMThimble 14mm to Suit 16mm Rope SSEach
4​
ROP0389CB
70​
ROPE LIST
90​
Item CodeFST0346M10 x 25 EYE BOLT 23MM EYE DIA SS-580-10Each
4​
ROP0389CB
70​
ROPE LIST
100​
Item CodeROP0010CMBolt Joint Ferrule Long 55mm (GC16-B)Each
4​
ROP0389CB
70​
ROPE LIST
110​
Item CodeFST0223-L25Allthread M10 SS 316 - Cut to Length 25mmEach
4​
ROP0389CB
70​
ROPE LIST
120​
Item CodeKRP5040Chain Boss Flat Surface M10 316 SSEach
4​
ROP0389CB
70​
ROPE LIST
130​
Item CodeFST0320SCREW BUTTON TORX S/S M8 X 25 (QTY1000)Each
4​
SHT0738CBC
180​
POWDERCOAT
20​
Item CodeSHT0738CMPfm Support Plate 5mm SS - for Cable Rope ClimbersEach
1​
SHT0738CBC
180​
POWDERCOAT
20​
Labour CodePOWDERCOATPowder Coating OperationMinutes
5​
SHT0738CBC
910​
EXT PREP
30​
Descriptor CodeFACTORY - EXTERNAL PREPExternal Preperation for Powdercoating$
1​
Wow, this works perfectly!!! The only issue is that I can only get it to work to 17,000 lines (which results in 40,000+ multi-level lines). I have managed to reduce our report to 73,000 lines so I'm expecting approx. 150,000-200,000 lines. I get the below error when I increase the lines to 18,000 or more. Is there anything that can be done? Would more CPU help or is it a limitation with the VBA..? I sincerely hope there is something that can be done because this completely resolves the issue. Thanks heaps for getting it to this stage!

1697166708410.png



1697166282624.png
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
First thing to try. Change these lines

ReDim aBom(1 To 300000, 1 To 9)

and

Private Sub GetBom(sPart As Variant, iLvl As Long)
 
Upvote 0
First thing to try. Change these lines

ReDim aBom(1 To 300000, 1 To 9)

and

Private Sub GetBom(sPart As Variant, iLvl As Long)
Same issue I'm afraid, "Out of stack space" - I tried reducing the 300000 to 200000 but no change 😩
 
Upvote 0
It probably has too many nested functions. This is something you have with recursion… maybe this weekend I have time to test a little.
 
Upvote 0
6. Yes, assumption correct - Note: a product is always a parent.
So, if an item exists in both col ItemCode & LineCode then it's not a product, right?
For example: CLM0337CB in the table in post #8, it's not a product, right?
However, when I tried @JEC code in post #18, CLM0337CB is considered as a product.:
Andy Howcroft - Multi-level Bill Of Materials explosion.xlsm
MNOPQRSTU
681CLM0337CB
692 FST2001120DISPATCH ASSY40Item CodeM10 Large Washer S/S 304 - Ø30ODEach4
702 CLM0337CM120DISPATCH ASSY10Item Code255mm Pitch Footing ChannelEach1
713 FABRICATION ASSY910FABRICATION20Labour CodeAssembly FabricationMinutes10
723 CLM0331CM910FABRICATION50Item CodeUniversal Footing Channel Type 1Each1
732 KRP5040120DISPATCH ASSY20Item CodeChain Boss Flat Surface M10 316 SSEach4
742 FST0320120DISPATCH ASSY30Item CodeSCREW BUTTON TORX S/S M8 X 25 (QTY1000)Each4
752 FST0002CM120DISPATCH ASSY50Item CodeSCREW BUTTON TORX S/S M10 X 16 (TW 111051) (800 QTY)Each4
762 DISPATCH ASSY120DISPATCH ASSY60Labour CodeAssemble as per PicklistMinutes10
Sheet5
 
Upvote 0
So, if an item exists in both col ItemCode & LineCode then it's not a product, right?
For example: CLM0337CB in the table in post #8, it's not a product, right?
However, when I tried @JEC code in post #18, CLM0337CB is considered as a product.:
Andy Howcroft - Multi-level Bill Of Materials explosion.xlsm
MNOPQRSTU
681CLM0337CB
692 FST2001120DISPATCH ASSY40Item CodeM10 Large Washer S/S 304 - Ø30ODEach4
702 CLM0337CM120DISPATCH ASSY10Item Code255mm Pitch Footing ChannelEach1
713 FABRICATION ASSY910FABRICATION20Labour CodeAssembly FabricationMinutes10
723 CLM0331CM910FABRICATION50Item CodeUniversal Footing Channel Type 1Each1
732 KRP5040120DISPATCH ASSY20Item CodeChain Boss Flat Surface M10 316 SSEach4
742 FST0320120DISPATCH ASSY30Item CodeSCREW BUTTON TORX S/S M8 X 25 (QTY1000)Each4
752 FST0002CM120DISPATCH ASSY50Item CodeSCREW BUTTON TORX S/S M10 X 16 (TW 111051) (800 QTY)Each4
762 DISPATCH ASSY120DISPATCH ASSY60Labour CodeAssemble as per PicklistMinutes10
Sheet5
Apologies, the Product, parent thing may have confused you. The essential thing is to retrieve all the BOMs as multi-level - some will be Products but must will be assemblies etc
 
Upvote 0
Apologies, the Product, parent thing may have confused you. The essential thing is to retrieve all the BOMs as multi-level - some will be Products but must will be assemblies etc
Sorry, I don't understand your wording: "some will be Products but must will be assemblies etc"
It's indeed confusing because your wording differs from the example you provided.
1. In post #1, the result only shows 'Product 1' and 'Product 2' as Level 1. However, there are no 'Assembly 1' to 'Assembly 4' displayed as Level 1. Are you suggesting that the result was actually incomplete, because there should be 'Assembly 1' to 'Assembly 4' displayed as Level 1 (not just as Level 2)?

2. The error you described in post #23, what was the value of iLv1 when the code stopped?
 
Upvote 0
It probably has too many nested functions. This is something you have with recursion… maybe this weekend I have time to test a little.
Hi - Just wondering if you managed to get chance to have a look at this one again...?
 
Upvote 0
I don’t have much time at the moment, unfortunately
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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