I have a BOM that I can get a structured look like this, where it pulls for all my products.
I'm trying to pull all members of a particular BOM recursively through VBA. so far I can get the top level items, but I cannot get anything beyond that. Can someone point me in the right direction with my code on what I need to do next? IF something better than recursion could work here I could do that as well, it was just my initial thought.
'getMembers gets all items of the member field
Function getMembers(member As String) As Variant
'declare range of BOM
Dim rng As range
Set rng = Worksheets("Allboms").range("All_Boms[name]")
Dim i As Integer
i = 0
Dim members() As String
ReDim members(1)
For Each cell In rng
If cell.Value = member Then
members(i) = cell.Offset(, 4).Value
i = i + 1
ReDim Preserve members(i)
End If
Next
getMembers = members
End Function
Sub getMemberItems()
'declare where product is
Dim product As String
product = range("C3").Value
Dim item As Variant
For Each item In getMembers(product)
Debug.print item
Next item
End Sub
