Silverwolph
New Member
- Joined
- Oct 10, 2022
- Messages
- 10
- Office Version
- 365
- 2019
- Platform
- Windows
Back in 2016 someone asked about finding the bom parent and tonyyy answered with this awesome code
My question is, could you expand this to show the entire parent level all the way to the end
So you have "8" and it has 4 or more parents "7, 6, 5, 4" which also has 2 parents 3 and 2, all ending up in 1
and you will end up with the entire string
A snip from my sheet
And so on, would this be possible
I´m working with a bom structure with 11 levels and if i look up a raw material it can have over 100 dif. parents
All again have new parents, but they all end up at the top number, 7 to 11 levels up.
And side question, is there a way of optimizing the code? with 6000+ lines it takes about 8 hours to run through it all
VBA Code:
Sub BOMParent3()
Dim LastRow As Long
Dim r As Range, r1 As Range, r2 As Range
Dim Lvl As Long, Parent As Long
Dim Level As String, Level2 As String
LastRow = Cells(Rows.Count, "D").End(xlUp).Row
For Each r In Range("D3:D" & LastRow)
Set r1 = r.Offset(0, -3)
Level = Replace(r1.Value, " ", "")
Level = Replace(Level, ".", "")
Lvl = Level
Parent = Lvl - 1
For Each r2 In Range(r1.Address, "A2")
Level2 = Replace(r2.Value, " ", "")
Level2 = Replace(Level2, ".", "")
Lvl = Level2
If Parent = Lvl Then r.Offset(0, -1) = r2.Offset(0, 3)
Next r2
Next r
End Sub
My question is, could you expand this to show the entire parent level all the way to the end
So you have "8" and it has 4 or more parents "7, 6, 5, 4" which also has 2 parents 3 and 2, all ending up in 1
and you will end up with the entire string
A snip from my sheet
>>>>>>>>>> | Pos. | Item Number | |||||||||
1 | 10 | 7659347 | |||||||||
.2 | 1 | 7658274 | 7659347 | ||||||||
..3 | 1 | 7657890 | 7658274 | 7659347 | |||||||
...4 | 1 | 7658287 | 7657890 | 7658274 | 7659347 | ||||||
....5 | 1 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 | |||||
.....6 | 1 | 4882118 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 | ||||
......7 | 1 | 4882117 | 4882118 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 | |||
.......8 | 1 | 4882115 | 4882117 | 4882118 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 | ||
........9 | 1 | 92500772 | 4882115 | 4882117 | 4882118 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 | |
.......8 | 2 | 4956389 | 4882117 | 4882118 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 | ||
........9 | 1 | 4882113 | 4956389 | 4882117 | 4882118 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 | |
.........10 | 1 | 92500772 | 4882113 | 4956389 | 4882117 | 4882118 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 |
........9 | 2 | 9511515 | 4956389 | 4882117 | 4882118 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 | |
.......8 | 3 | 4882102 | 4882117 | 4882118 | 7658205 | 7658287 | 7657890 | 7658274 | 7659347 |
And so on, would this be possible
I´m working with a bom structure with 11 levels and if i look up a raw material it can have over 100 dif. parents
All again have new parents, but they all end up at the top number, 7 to 11 levels up.
And side question, is there a way of optimizing the code? with 6000+ lines it takes about 8 hours to run through it all
Last edited by a moderator: