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
OUTPUT DATA:
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
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
<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: