+ Reply to Thread
Results 1 to 4 of 4

Print all the child till 5 levels

Hybrid View

  1. #1
    Registered User
    Join Date
    03-30-2023
    Location
    India
    MS-Off Ver
    365
    Posts
    18

    Print all the child till 5 levels

    I have a data like below, parent and child columns. Here a parent is calling the child and that child is calling another child and so on.

    Attached the sample worksheet with expected result

    Please let me know if there is any way to do this.

    Thanks
    Amith
    Attached Files Attached Files
    Last edited by amith4455; 03-30-2023 at 10:44 AM.

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Print all the child till 5 levels

    Maybe :
    Option Explicit
    Sub Test()
      Dim a, b, i As Long, j As Long, p As Long, s As String, z1 As New Collection, z2 As New Collection
      With Sheets("Sheet2")
        a = .Range("A1").CurrentRegion.Value
        ReDim b(1 To .Rows.Count, 1 To 1)
        For i = 3 To UBound(a, 1)
            On Error Resume Next
               z1.Add Key:=a(i, 1), Item:=New Collection
               z1(a(i, 1)).Add a(i, 2)
            On Error GoTo 0
        Next i
        For i = 3 To UBound(a, 1)
            s = a(i, 1) & "|" & a(i, 2)
            Rec s, z1, z2
            For j = 1 To z2.Count
                p = p + 1
                If j = 1 Then
                   b(p, 1) = s & "|" & z2(j)
                Else
                   b(p, 1) = "||" & z2(j)
                End If
            Next j
            Set z2 = Nothing
        Next i
        With .Range("M15").Resize(p)
          .Value = b
         .TextToColumns DataType:=xlDelimited, other:=True, otherchar:="|"
         .CurrentRegion.Borders.Weight = xlThin
        End With
      End With
    End Sub
    Private Sub Rec(ByVal s As String, ByRef z1 As Collection, ByRef z2 As Collection)
      Dim v1, v2
      v1 = Split(s, "|")
      v1 = v1(UBound(v1))
      On Error Resume Next
         Set v1 = z1(v1)
      On Error GoTo 0
      If TypeName(v1) = "Collection" Then
         For Each v2 In v1
             Rec s & "|" & v2, z1, z2
         Next v2
      Else
         z2.Add s
      End If
    End Sub
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Registered User
    Join Date
    03-30-2023
    Location
    India
    MS-Off Ver
    365
    Posts
    18

    Re: Print all the child till 5 levels

    Thank you so much. It works

  4. #4
    Registered User
    Join Date
    03-30-2023
    Location
    India
    MS-Off Ver
    365
    Posts
    18

    Re: Print all the child till 5 levels

    I am trying this for bulk data and its giving me "Out of stack space" error. Any idea how to fix this?
    Please find attached.

    Thank you
    Amith
    Attached Files Attached Files
    Last edited by davesexcel; 05-11-2023 at 10:49 AM. Reason: Long quotes are not required

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pull File info only from subfolders till 3 levels
    By rohitsekar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-24-2022, 05:43 AM
  2. [SOLVED] Summing Data With Criteria Q1, till Q2, till Q3 etc...
    By Jhon Mustofa in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-10-2021, 03:03 AM
  3. Juxtaposing successive levels from parent-child relational data
    By Marbleking in forum Excel Formulas & Functions
    Replies: 22
    Last Post: 07-08-2020, 11:41 PM
  4. [SOLVED] Sum child to parent, with multiple levels
    By HypeTaxx in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-23-2014, 10:38 AM
  5. Sum till the column till the date match
    By ursanil in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-02-2014, 06:29 AM
  6. Convert Pivot Table Tree to XML with 5 child levels
    By Neo444 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-12-2013, 03:45 PM
  7. Replies: 6
    Last Post: 12-03-2012, 05:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1