Separate indented hierarchy list into columns based on parent member

itsme2216

New Member
Joined
May 16, 2017
Messages
6
I have the below mentioned INPUT and I want to get the output as shared below under output header.
In my INPUT data in my column A contains the data which has different indenting level.
Basically the code should run on this range and check for the highest level of indenting and for each highest level of indenting it should put it under "Mapping 1" header and its subsequent lower levels in Mapping 2, 3 and 4.

INPUT DATA

VVjBQ.png
OUTPUT DATA:
e0jqa.png
I have developed a code which is giving me error on the below mentioned line: Run Time error 1004:

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">If currVal > arr(i,3)Then
ActiveCell
.Offset(k, arr(i,3)-1).Value = arr(i,1)
EndIf</code>overall code:-

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">Sub transposerowcolmulti()

Dim arr(1To8,0To3)AsVariant
Dim i AsLong, j AsLong

ActiveWorkbook
.Sheets("Input").Activate

For i = LBound(arr,1)To UBound(arr,1)

arr
(i,1)= range("A6").Offset(i,0).Value
arr
(i,2)= IsBold(range("A6").Offset(i,0))
arr
(i,3)= Level(range("A6").Offset(i,0))

Next i
Dim k AsLong, l AsLong
Dim prevVal AsLong, currVal AsLong


k
=0
l
=0

ActiveWorkbook
.Worksheets.Add
For i = LBound(arr,1)To UBound(arr,1)

If l =0Then
currVal
= arr(i,3)
l
= l +1
EndIf

If currVal = arr(i,3)Then
ActiveCell
.Offset(k, currVal -1).Value = arr(i,1)
EndIf

If currVal > arr(i,3)Then
ActiveCell
.Offset(k, arr(i,3)-1).Value = arr(i,1)
EndIf

If currVal < arr(i,3)Then
ActiveCell
.Offset(k, arr(i,3)-1).Value = arr(i,1)
EndIf

currVal
= arr(i,3)
k
= i
Next i


EndSub

Function Level(Optional cCell As range)
' LEVEL returns the outline level of the current row. It will not automatically update and therefore
' a recalculation Ctrl-Alt-F9 is required.

If cCell IsNothingThen
Set cCell = Application.Caller
EndIf
Level
= cCell.Rows.IndentLevel

EndFunction

Function IsBold(ByVal Cell As range)AsBoolean

IsBold
= Cell.Font.Bold

EndFunction</code>
Is my code incorrect will it not yield the output which I shared . My concept behind this code is to create a two dimensional array and then transpose the data from rows to columns based on indentation.

Please suggest me to modify this code to give the required results

I have posted this in stacksoverflow.com but didn't get any answer
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,215,045
Messages
6,122,836
Members
449,096
Latest member
Erald

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