Hi. I'm trying to display parent and child codes with the below code, but it seems that any child nodes after a single parent node do not display. If I move all the parent and child nodes to the top of the sheet then it works.
Any advice would be appreciated. Thanks
An example of my data is as follows:
Parent Child
ParentOne ChildOne
ParentOne ChildTwo
ParentOne ChildThree
ParentTwo
ParentThree ChildOne
ParentThree ChildTwo
Any advice would be appreciated. Thanks
An example of my data is as follows:
Parent Child
ParentOne ChildOne
ParentOne ChildTwo
ParentOne ChildThree
ParentTwo
ParentThree ChildOne
ParentThree ChildTwo
VBA Code:
Private Sub UserForm_Initialize()
Dim c As Range
Dim nParent As Node
Dim nChild As Node
'Parents are stored in Col A and child are stored in col B and C
For Each c In Sheet1.Range("a1:a" & Range("a" & Rows.Count).End(xlUp).Row)
'Setting parents--THIS PART IS WORKING
Set nParent = TreeView1.Nodes.Add(, , c.Value, c.Value)
'Setting child from col b and c: THIS PART IS NOT WORKING
Set nChild = TreeView1.Nodes.Add(nParent, tvwChild, c.Offset(0, 1).Value, c.Offset(0, 1).Value)
Set nChild = TreeView1.Nodes.Add(nParent, tvwChild, c.Offset(0, 2).Value, c.Offset(0, 2).Value)
Err.Clear
Next c
End Sub