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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Can you lay out an example of what the data looks like a sheet it would run against so we can see exactly what the code does when it runs (it depends on what the data and layout of the sheet looks like)?
 
Upvote 0
Thanks Joe. Hopefully this works as we cannot put addins on our work pc's
Below is what it starts with...

Purchase Order Part No Cost Date Period Require Rows Code 1
PO 23456 16402-2 18.53 06/02/14 1 3 A3
PO 23456 5H1626 0.53 06/03/14 2 3 A7
PO 23456 3N8821 1.87 06/03/14 2 4 J6
PO 23456 7Z8025 2.65 06/04/14 7 3 W42
PO 23456 1045 12.02 06/04/14 4 6 A4


Modified

Purchase Order Part No Cost Date Period Require Rows Code 1
PO 23456 16402-2 18.53 06/02/14 1 3 A3
PO 23456 16402-2 18.53 06/02/14 2 3 A3
PO 23456 16402-2 18.53 06/02/14 3 3 A3
PO 23456 5H1626 0.53 06/03/14 2 3 A7
PO 23456 5H1626 0.53 06/03/14 3 3 A7
PO 23456 5H1626 0.53 06/03/14 4 3 A7
PO 23456 3N8821 1.87 06/03/14 2 4 J6
PO 23456 3N8821 1.87 06/03/14 3 4 J6
PO 23456 3N8821 1.87 06/03/14 4 4 J6
PO 23456 3N8821 1.87 06/03/14 5 4 J6
PO 23456 7Z8025 2.65 06/04/14 7 3 W42
PO 23456 7Z8025 2.65 06/04/14 8 3 W42
PO 23456 7Z8025 2.65 06/04/14 9 3 W42
PO 23456 1045 12.02 06/04/14 4 6 A4
PO 23456 1045 12.02 06/04/14 5 6 A4
PO 23456 1045 12.02 06/04/14 6 6 A4
PO 23456 1045 12.02 06/04/14 7 6 A4
PO 23456 1045 12.02 06/04/14 8 6 A4
PO 23456 1045 12.02 06/04/14 9 6 A4
 
Upvote 0
I cannot use add-ins either, so I sometimes use Code Tags to lay-out the data, i.e.
Code:
A        B       C
Name     Age     Gender
Bob      25      Male
Cindy    29      Female
Tom      44      Male
It takes a little playing around (use Print Preview and keep going back and forth until things line-up).

Or, you can you just tell me what column each field resides in (I can't be certain where one field starts and another ends, whether you are starting in column A or some other column, or if there are any blank columns in the middle of your data)?

Thanks
 
Upvote 0
Sorry Joe. It looked fine until I sent it. Let me try your first method. Thanks
 
Upvote 0
Column A PO Number
Column B Part Number
Column C Cost
Column D Date
Column E Period
Column F Rows Required
Column G Code

Column A:D Copy
Column E goes up by one each
Column F indicates the number of required rows to replicate
Column G copies

Does this make sense on the top piece?
 
Upvote 0
The following is for column E starting from row 2 and going up by one increment each.
1
2
3
2
3
4
2
3
4
5
7
8
9
4
5
6
7
8
9
 
Upvote 0
I am not clear on using the code tags. Are they the same ones like
Code:
 ?
 
Upvote 0
Yes, and you use /Code in square brackets to close them off.
Or, just use the code brackets in the editor (looks like a pound sign).
 
Upvote 0
Thank you for your patience Joe.

******** language="JavaScript" ************************************************************************>
Purchase Register.xlsm
ABCDEFG
1PurchaseOrderPartNo.CostDatePeriodRowsCode
2PO2345616402-218.532006-02-1413A3
3PO234565H16260.532006-03-1423A7
4PO234563N88211.872006-03-1424J6
5PO234567Z80252.652006-04-1473W42
6PO23456104512.022006-04-1446A4
7
8Modified
9
10PurchaseOrderPartNo.CostDatePeriodRowsCode
11PO2345616402-218.532006-02-1413A3
12PO2345616402-218.532006-02-1423A3
13PO2345616402-218.532006-02-1433A3
14PO234565H16260.532006-03-1423A7
15PO234565H16260.532006-03-1433A7
16PO234565H16260.532006-03-1443A7
17PO234563N88211.872006-03-1424J6
18PO234563N88211.872006-03-1434J6
19PO234563N88211.872006-03-1444J6
20PO234563N88211.872006-03-1454J6
21PO234567Z80252.652006-04-1473W42
22PO234567Z80252.652006-04-1483W42
23PO234567Z80252.652006-04-1493W42
24PO23456104512.022006-04-1446A4
25PO23456104512.022006-04-1456A4
26PO23456104512.022006-04-1466A4
27PO23456104512.022006-04-1476A4
28PO23456104512.022006-04-1486A4
29PO23456104512.022006-04-1496A4
Sheet1
 
Upvote 0

Forum statistics

Threads
1,221,527
Messages
6,160,342
Members
451,638
Latest member
MyFlower

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