+ Reply to Thread
Results 1 to 10 of 10

Hierarchy

Hybrid View

  1. #1
    Registered User
    Join Date
    03-30-2008
    Posts
    6

    Hierarchy

    Hello, I could use some help with this. I have 2 columns of data (from Covu) exported to Excel. Column 1 contains all parents (equipment) column 2 contains equipment numbers. The Equipment numbers in the second column can also be parents and appear therefore in both columns. I would like to have the hierarchy over multible columns that I kann see how many levels of parent "child" equipment levels are there.

    any help appreciated!

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Say your data is in columns A and B, with A1 and B1 as headings.

    In a general module, insert the code

    Sub aaa()
      Range("D:H").ClearContents
      For Each ce In Range("B2:B11")
        strr = myfunc(ce.Offset(0, -1).Value, Range("B:B")) & "," & ce.Value
      
        arr = Split(strr, ",")
        outrow = Cells(Rows.Count, "D").End(xlUp).Offset(1, 0).Row
        outcol = 4
        For i = LBound(arr) To UBound(arr)
          Cells(outrow, outcol) = arr(i)
          outcol = outcol + 1
        Next i
      Next ce
      
      lastrow = Cells(Rows.Count, "D").End(xlUp).Row
      Range("D2:J" & lastrow).Sort key1:=Range("D2"), order1:=xlAscending, key2:=Range("E2"), order2:=xlAscending
    End Sub
    
    Function myfunc(x, rng As Range)
      If WorksheetFunction.CountIf(rng, x) = 0 Then
        myfunc = x
      Else
        Set findit = rng.Find(what:=x)
        myfunc = myfunc(findit.Offset(0, -1), rng) & "," & x
      End If
    End Function
    I've assumed that the output starts in column D, and for the sake of testing, my data only nested to 4 levels, so I've cleared out columns D:H just to be sure before running.

    See how this goes for a start.


    rylo

  3. #3
    Registered User
    Join Date
    03-30-2008
    Posts
    6
    Thank you very much for your help!

    The code you made for me is showing me how many levels in the hierarchy and work fine. Yes, I have my data in columns A & B (about 4000 rows). In column a number only appears if it is a parent. Column B has those numbers which are not parents and those which are parents themself. I have attached a screenshot to show a little better what I am looking for.

    Thank you!

  4. #4
    Registered User
    Join Date
    03-30-2008
    Posts
    6
    Now it's attached.

    Sorry about that.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Rather than a word document, can you create a small sample spreadsheet, zip it and attached the zipped file.

    Show how both the raw data, and your desired output are structured.


    rylo

  6. #6
    Registered User
    Join Date
    03-30-2008
    Posts
    6
    Thanks again!

    Have made a small example as you have requested. The real sheet has about 3500 rows. Thanks very much for your help.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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