Inserting Row(s) based on cell Value on same sheet

Billman101

New Member
Joined
Feb 14, 2019
Messages
9
Hello,

First time post/reply. I'm a pro at recording macros
:wink: but not so much on writing them. I'm trying to insert Row(s) based on cell value(s) that reside within my sheet.

Cell A3 has a value of N = 3 and I'd like to insert N rows at row 5 (two rows lower than 3). Then
at Cell A6 which has a value of N = 26 I'd like to insert N rows at row 8 (again two rows lower) and so on as depicted below:
[TABLE="class: cms_table, width: 229"]
<tbody>[TR]
[TD="align: right"]3[/TD]
[TD]Sunday[/TD]
[TD]2/17/2019[/TD]
[/TR]
[TR]
[TD="align: right"]26[/TD]
[TD]Monday[/TD]
[TD]2/18/2019[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[TD]Tuesday[/TD]
[TD]2/19/2019[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD]Wednesday[/TD]
[TD]2/20/2019[/TD]
[/TR]
[TR]
[TD="align: right"]19[/TD]
[TD]Thursday[/TD]
[TD]2/21/2019[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[TD]Friday[/TD]
[TD]2/22/2019[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD]Saturday[/TD]
[TD]2/23/2019[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Thanks for any insight you have,
Bill
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi & welcome to MrExcel.
How about
Code:
Sub Billman101()
   Dim i As Long, Qty As Long
   
   For i = Range("A" & Rows.Count).End(xlUp).Row To 3 Step -3
      Rows(i + 2).Resize(Cells(i, 1)).Insert
   Next i
End Sub
 
Upvote 0
Thanks Fluff,

This seems to work but once it runs it returns an error. When I debug the following is highlighted:

Rows(i + 2).Resize(Cells(i, 1)).Insert

Thanks.
 
Upvote 0
Do you have numbers in every cell from A3 to the end of the column?
 
Upvote 0
Hi Fluff,

Thanks for help.

I've pasted a portion of my sheet below:

[TABLE="width: 245"]
<colgroup><col width="41" style="width: 31pt; mso-width-source: userset; mso-width-alt: 1499;"> <col width="107" style="width: 80pt; mso-width-source: userset; mso-width-alt: 3913;"> <col width="92" style="width: 69pt; mso-width-source: userset; mso-width-alt: 3364;"> <col width="87" style="width: 65pt; mso-width-source: userset; mso-width-alt: 3181;"> <tbody>[TR]
[TD="width: 41, bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: #A9D08E"]Component Asset Group Description (Level 7)[/TD]
[TD="width: 92, bgcolor: #A9D08E"]WO Number[/TD]
[TD="width: 87, bgcolor: #A9D08E"]WO Status[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: black"] [/TD]
[TD="width: 92, bgcolor: black"] [/TD]
[TD="width: 87, bgcolor: black"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, align: right"]2[/TD]
[TD="width: 107, bgcolor: yellow"]Sunday[/TD]
[TD="width: 92, bgcolor: yellow"]2/17/2019[/TD]
[TD="width: 87, bgcolor: yellow"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: transparent"] [/TD]
[TD="width: 92, bgcolor: transparent"] [/TD]
[TD="width: 87, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: #0D0D0D"] [/TD]
[TD="width: 92, bgcolor: #0D0D0D"] [/TD]
[TD="width: 87, bgcolor: #0D0D0D"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, align: right"]26[/TD]
[TD="width: 107, bgcolor: yellow"]Monday[/TD]
[TD="width: 92, bgcolor: yellow"]2/18/2019[/TD]
[TD="width: 87, bgcolor: yellow"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: transparent"] [/TD]
[TD="width: 92, bgcolor: transparent"] [/TD]
[TD="width: 87, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: #0D0D0D"] [/TD]
[TD="width: 92, bgcolor: #0D0D0D"] [/TD]
[TD="width: 87, bgcolor: #0D0D0D"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, align: right"]16[/TD]
[TD="width: 107, bgcolor: yellow"]Tuesday[/TD]
[TD="width: 92, bgcolor: yellow"]2/19/2019[/TD]
[TD="width: 87, bgcolor: yellow"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: transparent"] [/TD]
[TD="width: 92, bgcolor: transparent"] [/TD]
[TD="width: 87, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: #0D0D0D"] [/TD]
[TD="width: 92, bgcolor: #0D0D0D"] [/TD]
[TD="width: 87, bgcolor: #0D0D0D"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, align: right"]17[/TD]
[TD="width: 107, bgcolor: yellow"]Wednesday[/TD]
[TD="width: 92, bgcolor: yellow"]2/20/2019[/TD]
[TD="width: 87, bgcolor: yellow"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: transparent"] [/TD]
[TD="width: 92, bgcolor: transparent"] [/TD]
[TD="width: 87, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: #0D0D0D"] [/TD]
[TD="width: 92, bgcolor: #0D0D0D"] [/TD]
[TD="width: 87, bgcolor: #0D0D0D"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, align: right"]19[/TD]
[TD="width: 107, bgcolor: yellow"]Thursday[/TD]
[TD="width: 92, bgcolor: yellow"]2/21/2019[/TD]
[TD="width: 87, bgcolor: yellow"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: transparent"] [/TD]
[TD="width: 92, bgcolor: transparent"] [/TD]
[TD="width: 87, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="bgcolor: #0D0D0D"] [/TD]
[TD="bgcolor: #0D0D0D"] [/TD]
[TD="bgcolor: #0D0D0D"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, align: right"]16[/TD]
[TD="width: 107, bgcolor: yellow"]Friday[/TD]
[TD="width: 92, bgcolor: yellow"]2/22/2019[/TD]
[TD="width: 87, bgcolor: yellow"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: transparent"] [/TD]
[TD="width: 92, bgcolor: transparent"] [/TD]
[TD="width: 87, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="bgcolor: #0D0D0D"] [/TD]
[TD="bgcolor: #0D0D0D"] [/TD]
[TD="bgcolor: #0D0D0D"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, align: right"]2[/TD]
[TD="width: 107, bgcolor: yellow"]Saturday[/TD]
[TD="width: 92, bgcolor: yellow"]2/23/2019[/TD]
[TD="width: 87, bgcolor: yellow"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 107, bgcolor: transparent"] [/TD]
[TD="width: 92, bgcolor: transparent"] [/TD]
[TD="width: 87, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="bgcolor: #0D0D0D"] [/TD]
[TD="bgcolor: #0D0D0D"] [/TD]
[TD="bgcolor: #0D0D0D"] [/TD]
[/TR]
</tbody>[/TABLE]

What I need to have done is add space based on what's in col. A cells. Then paste in this space data from either an external file or within a tab in this spreadsheet.

The space needed to paste data from Col. A to L.

Many thanks,
 
Upvote 0
Could you please answer my question? ;)
 
Upvote 0
Oops, I should have said
Do you have numbers in every 3rd cell from A3 to the end of the column?
I ask because the code I supplied works for the data you posted.
 
Upvote 0
If you run this
Code:
Sub chk()
   MsgBox Range("A" & Rows.Count).End(xlUp).Row
End Sub
What does the Msgbox say?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
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