How to generate tree structure dynamically??

saratchandra

New Member
Joined
Mar 16, 2018
Messages
6
Code:
Set myNode = TreeView1.Nodes.Add(, , "r", Cells(50, 7).text) 
Set myNode = TreeView1.Nodes.Add("r", tvwChild, "child1", Cells(51, 7).text) 
Set myNode = TreeView1.Nodes.Add("r", tvwChild, "child2", Cells(52, 7).text) 
Set myNode = TreeView1.Nodes.Add("r", tvwChild, "child3", Cells(53, 7).text)  
Set myNode = TreeView1.Nodes.Add("r", tvwChild, "child4", Cells(54, 7).text)  
Set myNode = TreeView1.Nodes.Add("r", tvwChild, "child15", Cells(60, 7).text) 
Set myNode = TreeView1.Nodes.Add("r", tvwChild, "child16", Cells(68, 7).text) 


Set myNode = TreeView1.Nodes.Add("child4", tvwChild, "child13", Cells(56, 7).text) 
Set myNode = TreeView1.Nodes.Add("child4", tvwChild, "child14", Cells(57, 7).text) 


Set myNode = TreeView1.Nodes.Add("child15", tvwChild, "child22", Cells(62, 7).text) 
Set myNode = TreeView1.Nodes.Add("child15", tvwChild, "child23", Cells(65, 7).text) 
Set myNode = TreeView1.Nodes.Add("child15", tvwChild, "child17", Cells(69, 7).text) 


Set myNode = TreeView1.Nodes.Add("child17", tvwChild, "child24", Cells(71, 7).text) 
Set myNode = TreeView1.Nodes.Add("child17", tvwChild, "child18", Cells(72, 7).text) 


Set myNode = TreeView1.Nodes.Add("child18", tvwChild, "child25", Cells(74, 7).text)
Set myNode = TreeView1.Nodes.Add("child18", tvwChild, "child19", Cells(75, 7).text) 
Set myNode = TreeView1.Nodes.Add("child19", tvwChild, "child26", Cells(77, 7).text) 
Set myNode = TreeView1.Nodes.Add("child19", tvwChild, "child20", Cells(78, 7).text) 


Set myNode = TreeView1.Nodes.Add("child20", tvwChild, "child27", Cells(80, 7).text) 
Set myNode = TreeView1.Nodes.Add("child20", tvwChild, "child21", Cells(81, 7).text)


Set myNode = TreeView1.Nodes.Add("child21", tvwChild, "child28", Cells(83, 7).text) 


Set myNode = TreeView1.Nodes.Add(, , "r1", Cells(95, 7).text)
Set myNode = TreeView1.Nodes.Add("r1", tvwChild, "child5", Cells(96, 7).text) 
Set myNode = TreeView1.Nodes.Add("r1", tvwChild, "child6", Cells(97, 7).text) 


Set myNode = TreeView1.Nodes.Add(, , "r2", Cells(99, 7).text) 
Set myNode = TreeView1.Nodes.Add("r2", tvwChild, "child7", Cells(100, 7).text) 


Set myNode = TreeView1.Nodes.Add(, , "r3", Cells(102, 7).text) 
Set myNode = TreeView1.Nodes.Add("r3", tvwChild, "child8", Cells(103, 7).text) 
Set myNode = TreeView1.Nodes.Add("r3", tvwChild, "child9", Cells(104, 7).text) 


Set myNode = TreeView1.Nodes.Add(, , "r4", Cells(106, 7).text) 
Set myNode = TreeView1.Nodes.Add("r4", tvwChild, "child10", Cells(107, 7).text) 
Set myNode = TreeView1.Nodes.Add("r4", tvwChild, "child11", Cells(108, 7).text) 
Set myNode = TreeView1.Nodes.Add("r4", tvwChild, "child12", Cells(109, 7).text)
In the above code i am providing the text manually by giving row number in excel sheet. But i need to generate the tree dynamically by taking the row number automatically from my excel sheet. And how can i link the child of one node as a parent of another node.

Please provide me the logic in generating the tree or with the VBA Script for generating the tree.

Regards,
Sarath.
 
Last edited by a moderator:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,004
Messages
6,122,656
Members
449,091
Latest member
peppernaut

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