Outline numbering & blanks between cells

dancingdata

New Member
Joined
Aug 18, 2017
Messages
6
Hello,,

I am trying to create an outline numbering list from a data table which look like below:

[TABLE="width: 173"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]# of Criteria[/TD]
[TD]Numbering Category[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]1.1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1.2[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]1.3[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2.1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Result to be as follow:

4 1.1 1.1.1
4 1.1 1.1.2
4 1.1 1.1.3
4 1.1 1.1.4
3 1.2 1.2.1
3 1.2 1.2.2
3 1.2 1.2.3..etc

Can you help with a VBA code that can automate this process? Basically I need the VBA to insert new cells based on the number of criteria then generate the numbering for each numbering category.

Appreciate your support.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Code:
Sub dancingdata()

Dim lRow As Long
Dim criteria As Long

lRow = Cells(Rows.Count, 1).End(xlUp).Row

For i = lRow To 1 Step -1

    criteria = Cells(i, 1).Value - 1
    
    Range(Cells(i, 1).Offset(1), Cells(i, 1).Offset(criteria)).EntireRow.Insert
       
    Cells(i, 1).Offset(0, 2).Value = Cells(i, 1).Offset(0, 1).Value & ".1"
        
    ActiveSheet.Range(Cells(i, 1), Cells(i, 3)).AutoFill (ActiveSheet.Range(Cells(i, 1), Cells(i, 3).Offset(criteria)))
        

Next i

End Sub
 
Last edited:
Upvote 0
It's because your actual data is "text" and not numbers. Does this have to remain as a text or can it be converted to a number?
 
Upvote 0
No does not matter for me whether its a number or a text.. BTW, I tried to figure out the problem and its seems the code does not handle the numbering when the repetition is equal to one.. am I right?

Example:

[TABLE="width: 192"]
<colgroup><col width="64" style="width:48pt"> <col width="64" style="width:48pt"> <col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]2[/TD]
[TD="class: xl65, width: 64"]2.1[/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]2.1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]3.1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl65"][/TD]
[TD="align: right"]0.1[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl65"][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl65"]1[/TD]
[TD="class: xl65"]3.2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl65"]3[/TD]
[TD="class: xl65"]3.3[/TD]
[TD]3.3.1[/TD]
[/TR]
[TR]
[TD="class: xl65"]3[/TD]
[TD="class: xl65"]3.3[/TD]
[TD]3.3.2[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Yes. I didn't account for 1 as criteria of whether to insert no rows. The following should address that.

Code:
Sub dancingdata()
Dim lRow As Long
Dim criteria As Long
Dim rFill As String
Dim rFill2 As String

lRow = Cells(Rows.Count, 1).End(xlUp).Row

For i = lRow To 1 Step -1

        If Cells(i, 1).Value - 1 >= 1 Then
                 criteria = Cells(i, 1).Value - 1
                 Range(Cells(i, 1).Offset(1), Cells(i, 1).Offset(criteria)).EntireRow.Insert
            
                 Cells(i, 1).Offset(0, 2).Value = Cells(i, 1).Offset(0, 1).Value & ".1"
                 
                 Range(Cells(i, 1).Offset(1), Cells(i, 2).Offset(criteria)).Value = Range(Cells(i, 1), Cells(i, 2)).Value
                
                 rFill = Cells(i, 3).Address
                 rFill2 = Cells(i, 3).Offset(criteria).Address
                 ActiveSheet.Range(Cells(i, 3).Address).AutoFill (ActiveSheet.Range(rFill, rFill2))
                 
           Else:
                Cells(i, 1).Offset(0, 2).Value = Cells(i, 1).Offset(0, 1).Value & ".1"
        End If
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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