another bill of material question

padil110

New Member
Joined
Mar 22, 2019
Messages
6
so i got some great help on a bill of material question a month ago. now that i have been running the new system, the bills of materials are not set up traditionally. Usually the whole bill is exploded with all levels. If i have a bunch of bills in a query that are not exploded in levels, how can i flag all necessary materials for a specific bill if they are not linked together in a bill master? Im trying to put together a single column that flags all components of "car" when i look up the bill for "car", in column C. you can see that Car (level1) has 4 components (level2 - wheels, cabin, etc..) while cabin has its own bill starting in A11 (level 3 - steering wheel, belts, etc....). Is it possible to flag all components of "car" for all parts in column C?

ABC
1ParentComponent
2carwheels
3carcabin
4carmotor
5carseats
6wheelsrubber
7wheelsrims
8motorblock
9motorpiston
10motordistributor
11cabinsteering wheel
12cabinbelts
13cabindashboard
14shirtfabric
15fabricwhool
16seatsleather
17seatscusion
18pistonsteel
19blocksteel
20distributorrubber
21distributorplastic

<tbody>
</tbody>

Any help would be much appreciated. I know it must be an array formula, but i have trouble writing formulas with row and column, (I'm trying to learn)
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Thanks for your reply Dante, Here is the expected result (in column C and D). [FONT=&quot]I have created a query to extract bills of material form our ERP system. The bills for the full assembly are massive, up to 500 items. The problem is that they are not all exploded or linked in a parent/ child fashion. for instance, the bill for the top item will have the first level parent/ child, but then the child has its own bill which isn't indented in the first bill. Im trying to make a simple, refreshable, planning program to tell us what materials we need per the total bill of material (all levels). Here is what I'm talking about. column A and B are the way the query generates the data, all parent/ child bills are organized in 1-2 levels. I want to display C and D, which is a full linked bill of material. Its really tough, and i am struggling. Any help would be much [/FONT]appreciated,




ABCD
1ParentChild1Car
2carwheels2wheels
3carcabin3rubber
4carmotor3rims
5carseats2cabin
6wheelsrubber3steering wheel
7wheelsrims3belts
8motorblock3dashboard
9motorpiston2motor
10motordistributor3block
11cabinsteering wheel4steel
12cabinbelts3piston
13cabindashboard4steel
14shirtfabric3distributor
15fabricwhool4rubber
16seatsleather4plastic
17seatscusion2seats
18pistonsteel3leather
19blocksteel3cusion
20distributorrubber1shirt
21distributorplastic2fabric

<colgroup><col width="65" span="5" style="width: 65pt;"></colgroup><tbody>
</tbody>

<colgroup><col width="65" span="5" style="width: 65pt;"></colgroup><tbody></tbody>
 
Upvote 0
Try this for results starting "C1":-

NB:- You appear to have a link like "car-shirt" missing from your data !!!
Code:
[COLOR="Navy"]Sub[/COLOR] MG14Apr45
[COLOR="Navy"]Dim[/COLOR] rParents [COLOR="Navy"]As[/COLOR] Range, rNode [COLOR="Navy"]As[/COLOR] Range, rOut [COLOR="Navy"]As[/COLOR] Range, mRng [COLOR="Navy"]As[/COLOR] Range
    [COLOR="Navy"]Dim[/COLOR] lRow [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Dic [COLOR="Navy"]As[/COLOR] Object, oMax, oRw
[COLOR="Navy"]Dim[/COLOR] Dn [COLOR="Navy"]As[/COLOR] Range, Q [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] rOut = Range("D1")
  rOut(1, 0) = 1
   
   [COLOR="Navy"]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
   Dic.CompareMode = vbTextCompare
      [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Range("A2", Range("A" & Rows.Count).End(xlUp))
         [COLOR="Navy"]If[/COLOR] Not Dic.exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
              Dic.Add Dn.Value, CreateObject("scripting.dictionary")
              Dic(Dn.Value).Add Dn.Offset(, 1).Value, Array(Dn, Dn.Offset(, 1))
         [COLOR="Navy"]ElseIf[/COLOR] Not Dic(Dn.Value).exists(Dn.Offset(, 1).Value) [COLOR="Navy"]Then[/COLOR]
                Dic(Dn.Value).Add Dn.Offset(, 1).Value, Array(Dn, Dn.Offset(, 1))
         [COLOR="Navy"]End[/COLOR] If
      [COLOR="Navy"]Next[/COLOR] Dn
  Call DisplayTree([a2], Dic, rOut, lRow, 1)
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
[COLOR="Navy"]Sub[/COLOR] DisplayTree(ByVal sParent [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Dic, rOut [COLOR="Navy"]As[/COLOR] Range, ByRef lRow [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] ByVal lLevel [COLOR="Navy"]As[/COLOR] Long)

    [COLOR="Navy"]Dim[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Dn [COLOR="Navy"]As[/COLOR] Range, rr [COLOR="Navy"]As[/COLOR] Range
    [COLOR="Navy"]Dim[/COLOR] vChild

     [COLOR="Navy"]If[/COLOR] lRow = 0 [COLOR="Navy"]Then[/COLOR] rOut = sParent: lRow = 1

        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] vChild [COLOR="Navy"]In[/COLOR] Dic(sParent)
            lRow = lRow + 1
            rOut(lRow, 1) = vChild
            rOut(lRow, 0) = lLevel + 1
          [COLOR="Navy"]If[/COLOR] Dic.exists(vChild) [COLOR="Navy"]Then[/COLOR]
            Call DisplayTree(vChild, Dic, rOut, lRow, lLevel + 1)
         [COLOR="Navy"]End[/COLOR] If

[COLOR="Navy"]Next[/COLOR] vChild
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

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