build a column that shows parent child relationships of rows based on a column of heading numbers

cliff_sadler

New Member
Joined
Mar 16, 2016
Messages
1
Greetings, new to the forum.

I have a flat .csv file that represents a document with sections and sub sections that will be imported into a requirements management application.
This application understands hierarchy, and will recreate it if I can provide a mapping of parent and children rows. I cannot post an attachment, but will describe as follows:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Identifier[/TD]
[TD]ParentBinding[/TD]
[TD]Section[/TD]
[TD]isHeading[/TD]
[TD]PrimaryText[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]1[/TD]
[TD]TRUE[/TD]
[TD]SCOPE[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD][/TD]
[TD]FALSE[/TD]
[TD]Text Intro[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD]1.1[/TD]
[TD]TRUE[/TD]
[TD]Sub Heading[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD]1.1.A[/TD]
[TD]FALSE[/TD]
[TD]Requirement 1
[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[TD]1.1.B[/TD]
[TD]FALSE[/TD]
[TD]Requirement 2[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD][/TD]
[TD]1.2[/TD]
[TD]TRUE[/TD]
[TD]Sub Heading[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][/TD]
[TD]1.2.1[/TD]
[TD]TRUE[/TD]
[TD]Sub Sub Heading[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD][/TD]
[TD]1.2.1.A[/TD]
[TD]FALSE[/TD]
[TD]Requirement 3[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD][/TD]
[TD]1.2.1.A.1[/TD]
[TD]FALSE[/TD]
[TD]Sub Requirement 3[/TD]
[/TR]
</tbody>[/TABLE]

This is what I have. In order to get the application to recreate this hierarchy, I have to specify the Identifier of the Parent row in ParentBinding, as follows:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Identifier[/TD]
[TD]ParentBinding[/TD]
[TD]Section[/TD]
[TD]isHeading[/TD]
[TD]PrimaryText[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]""[/TD]
[TD]1[/TD]
[TD]TRUE[/TD]
[TD]SCOPE[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD][/TD]
[TD]FALSE[/TD]
[TD]Text Intro[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD]1.1[/TD]
[TD]TRUE[/TD]
[TD]Sub Heading[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]3[/TD]
[TD]1.1.A[/TD]
[TD]FALSE[/TD]
[TD]Requirement 1
[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]3[/TD]
[TD]1.1.B[/TD]
[TD]FALSE[/TD]
[TD]Requirement 2[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]1[/TD]
[TD]1.2[/TD]
[TD]TRUE[/TD]
[TD]Sub Heading[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]6[/TD]
[TD]1.2.1[/TD]
[TD]TRUE[/TD]
[TD]Sub Sub Heading[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]7[/TD]
[TD]1.2.1.A[/TD]
[TD]FALSE[/TD]
[TD]Requirement 3[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]8[/TD]
[TD]1.2.1.A.1[/TD]
[TD]FALSE[/TD]
[TD]Sub Requirement 3

[/TD]
[/TR]
</tbody>[/TABLE]

I can hand jam the top level "" value as there's only 11 or sections per document. The lower levels, and leaf rows of requirements or information are in the thousands, so doing this by hand will be very tedious. It is true that the information rows currently do not have section identifiers, and those could be added if necessary to get the solution to work. In this case, the Section number for Identifier 2's row would also be 1.1 (child of Section 1).

I have started with a formula to count the dots in Section, and add one to get the levels of each row, and now need some way to look back to find the parent.
=(LEN(C2)-LEN(SUBSTITUTE(C2,".","")))+1

Thanks for looking!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try this macro.
It worked on your sample. But if it doesn't work on your real data, it means that I've made some false assumption regarding the data. In this case I need you to upload your workbook sample (without sensitive data) somewhere (maybe via dropbox.com).

Code:
Sub a928370()
Dim r As Range
Dim rr As Long
Dim x As String

rr = Range("A" & Rows.count).End(xlUp).row
For Each r In Range("C2:C" & rr)
    If InStr(1, r, ".") = 0 And Len(r) > 0 Then
      x = r.Value
      GoTo pass:
    End If

    If Len(r) = 0 Or Len(r) = 3 Then
      r.Offset(0, -1) = x
    ElseIf Len(r) > Len(r.Offset(-1, 0)) Then
      r.Offset(0, -1) = r.Offset(-1, -2)
      ElseIf Len(r) = Len(r.Offset(-1, 0)) Then
      r.Offset(0, -1) = r.Offset(-1, -1)
    End If
pass:
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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