Need a loop macro to add x number of rows

hanalino

New Member
Joined
Dec 4, 2018
Messages
1
Category GroupCenterLevel
LOVCABCDE1
NCMGABCDE1
SVCSABCDE1
LOVCFGHIJ1
NCMGFGHIJ1
SVCSFGHIJ1
LOVCKLMNO1
NCMGKLMNO1
SVCSKLMNO1
LOVCPQRST1
NCMGPQRST1
SVCSPQRST1
<colgroup><col width="99" style="width: 74pt; mso-width-source: userset; mso-width-alt: 3620;"> <col width="64" style="width: 48pt;" span="2"> <tbody> </tbody>
My current data set looks like the above: 3 Category Groups for each Center = Level 1. I need a loop macro to add 3 additional levels of each category group for every new Center (total of 9 additional rows added for each Center)

It needs to look like this:
Category GroupCenterLevel
LOVCABCDE1
NCMGABCDE1
SVCSABCDE1
LOVCABCDE2
NCMGABCDE2
SVCSABCDE2
LOVCABCDE3
NCMGABCDE3
SVCSABCDE3
LOVCABCDE4
NCMGABCDE4
SVCSABCDE4
LOVCFGHIJ1
NCMGFGHIJ1
SVCSFGHIJ1
LOVCFGHIJ2
NCMGFGHIJ2
SVCSFGHIJ2
LOVCFGHIJ3
NCMGFGHIJ3
SVCSFGHIJ3
LOVCFGHIJ4
NCMGFGHIJ4
SVCSFGHIJ4
LOVCKLMNO1
NCMGKLMNO1
SVCSKLMNO1
LOVCKLMNO2
NCMGKLMNO2
SVCSKLMNO2
LOVCKLMNO3
NCMGKLMNO3
SVCSKLMNO3
LOVCKLMNO4
NCMGKLMNO4
SVCSKLMNO4
LOVCPQRST1
NCMGPQRST1
SVCSPQRST1
LOVCPQRST2
NCMGPQRST2
SVCSPQRST2
LOVCPQRST3
NCMGPQRST3
SVCSPQRST3
LOVCPQRST4
NCMGPQRST4
SVCSPQRST4
<colgroup><col width="99" style="width: 74pt; mso-width-source: userset; mso-width-alt: 3620;"> <col width="64" style="width: 48pt;" span="2"> <tbody> </tbody>

Thanks!!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi hanalino,

Try this code and let me know if it works for you:

Code:
Sub foo()
    Dim rngCategory         As Excel.Range
    Dim lngRow              As Long
    Dim lngCount            As Long
    Dim lngStep
    
    With ActiveSheet
        Set rngCategory = [COLOR=#ff0000].Range("A2:B13")[/COLOR]
        For lngRow = 2 To rngCategory.Rows.Count + 1 Step 3
            lngCount = Application.CountA(.Range("E:E")) + 1
            For lngStep = 0 To 3
                .Range("E" & lngCount + lngStep * 3 & ":F" & lngCount + 2 + lngStep * 3).Value = _
                    .Range("A" & lngRow & ":B" & lngRow + 2).Value
                .Range("G" & lngCount + lngStep * 3 & ":G" & lngCount + 2 + lngStep * 3).Value = lngStep + 1
            Next lngStep
        Next lngRow
    End With
    
    Set rngCategory = Nothing
End Sub

I'm assuming that your original dataset is in cells A2:B13 (can be changed), and you are dropping your results to columns E-G.
 
Upvote 0

Forum statistics

Threads
1,221,443
Messages
6,159,907
Members
451,601
Latest member
terrynelson55

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