Set up numbers into MultiLevel tree

Forestq

Active Member
Joined
May 9, 2010
Messages
482
Hi,

I need to generate number into column F, based on hierarchy (col B:D), below is excel examaple:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[TD]F
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Looking Numbers
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]A1
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD][/TD]
[TD]A1.1
[/TD]
[TD][/TD]
[TD][/TD]
[TD]101
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD][/TD]
[TD]A1.2
[/TD]
[TD][/TD]
[TD][/TD]
[TD]201
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD][/TD]
[TD]A1.3
[/TD]
[TD][/TD]
[TD][/TD]
[TD]301
[/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD][/TD]
[TD][/TD]
[TD]A1.3.1
[/TD]
[TD][/TD]
[TD]10301
[/TD]
[/TR]
[TR]
[TD]8
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9
[/TD]
[TD]B1
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2
[/TD]
[/TR]
[TR]
[TD]10
[/TD]
[TD][/TD]
[TD]B1.1
[/TD]
[TD][/TD]
[TD][/TD]
[TD]102
[/TD]
[/TR]
[TR]
[TD]11
[/TD]
[TD][/TD]
[TD]B1.2
[/TD]
[TD][/TD]
[TD][/TD]
[TD]202
[/TD]
[/TR]
[TR]
[TD]12
[/TD]
[TD][/TD]
[TD][/TD]
[TD]B1.2.1
[/TD]
[TD][/TD]
[TD]10202
[/TD]
[/TR]
[TR]
[TD]13
[/TD]
[TD][/TD]
[TD][/TD]
[TD]B1.2.2
[/TD]
[TD][/TD]
[TD]20202
[/TD]
[/TR]
[TR]
[TD]14
[/TD]
[TD][/TD]
[TD]B1.3
[/TD]
[TD][/TD]
[TD][/TD]
[TD]302
[/TD]
[/TR]
[TR]
[TD]15
[/TD]
[TD][/TD]
[TD]B1.4
[/TD]
[TD][/TD]
[TD][/TD]
[TD]402
[/TD]
[/TR]
[TR]
[TD]16
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]17
[/TD]
[TD]C1
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]3
[/TD]
[/TR]
[TR]
[TD]18
[/TD]
[TD][/TD]
[TD]C1.1
[/TD]
[TD][/TD]
[TD][/TD]
[TD]103
[/TD]
[/TR]
[TR]
[TD]19
[/TD]
[TD][/TD]
[TD][/TD]
[TD]C1.1.1
[/TD]
[TD][/TD]
[TD]10103
[/TD]
[/TR]
[TR]
[TD]20
[/TD]
[TD][/TD]
[TD][/TD]
[TD]C1.1.2
[/TD]
[TD][/TD]
[TD]20103
[/TD]
[/TR]
</tbody>[/TABLE]


I know only how to set A1, B1 and C1 value.
Code:
ws_c = ws1.Cells(Rows.Count, "D").End(xlUp).Row
Dim Lev1, Lev2, Lev3 As Long
Lev1 = 1
    For i = 3 To ws_c
    
        If ws1.Range("B" & i).Value <> "" Then
           ws1.Range("F" & i).Value = Lev1
           Lev1 = Lev1 + 1
        End If
    Next
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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