Modify VBA to suit

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
Below is code from a Microsoft site that creates new rows each time it sees a number eg. if the number is 12 it will generate an additional 11 rows. Everything works great but I need to add the number 1 to each cell in column E when it creates each new row. If the number is 1 it will populate to 2 and then to 3 etc. How can this be modified to accomplish this?


Code:
Public Sub InsBelow()
Dim lngStartRow As Long
Dim lngEndRow As Long
Dim m As Integer
Dim n As Long
With ActiveSheet
lngStartRow = Range("F" & CStr(Application.Rows.Count)).End(xlUp).Row
lngEndRow = 1
For n = lngStartRow To lngEndRow Step -1
If IsNumeric(Range("F" & CStr(n)).Value) And Range("F" & CStr(n)).Value <> "" Then
    Rows(n + 1).Resize(Range("F" & n).Value - 1).Insert
     Rows(n).Resize(Range("F" & n).Value).FillDown
        End If
    Next n
End With
End Sub
 
A few minor edits to your code in post #14 will give you the expected results you posted in post #16:
Code:
    Dim lngStartRow As Long
    Dim lngEndRow As Long
    Dim m As Integer
    Dim n As Long
    
    With ActiveSheet
        lngStartRow = Range("F" & CStr(Application.Rows.Count)).End(xlUp).Row
        lngEndRow = 1
        For n = lngStartRow To lngEndRow Step -1
            If IsNumeric(Range("F" & CStr(n)).Value) And Range("F" & CStr(n)).Value <> "" Then
                Rows(n + 1).Resize(Range("F" & n).Value).Insert
                Rows(n).Resize(Range("F" & n).Value + 1).FillDown
            End If
        Next n
    End With
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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