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:

# of CriteriaNumbering Category
41.1
31.2
41.3
42.1

<colgroup><col><col></colgroup><tbody>
</tbody>
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

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

22.1
12.1
13.1
0.1
13.2
33.33.3.1
33.33.3.2

<colgroup><col width="64" style="width:48pt"> <col width="64" style="width:48pt"> <col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>
 
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,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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