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:
IdentifierParentBindingSectionisHeadingPrimaryText
11TRUESCOPE
2FALSEText Intro
31.1TRUESub Heading
41.1.AFALSERequirement 1
51.1.BFALSERequirement 2
61.2TRUESub Heading
71.2.1TRUESub Sub Heading
81.2.1.AFALSERequirement 3
91.2.1.A.1FALSESub Requirement 3

<tbody>
</tbody>

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:

IdentifierParentBindingSectionisHeadingPrimaryText
1""1TRUESCOPE
21FALSEText Intro
311.1TRUESub Heading
431.1.AFALSERequirement 1
531.1.BFALSERequirement 2
611.2TRUESub Heading
761.2.1TRUESub Sub Heading
871.2.1.AFALSERequirement 3
981.2.1.A.1FALSESub Requirement 3


<tbody>
</tbody>

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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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,215,378
Messages
6,124,601
Members
449,173
Latest member
chandan4057

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