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:
3Sunday2/17/2019
26Monday2/18/2019
16Tuesday2/19/2019
17Wednesday2/20/2019
19Thursday2/21/2019
16Friday2/22/2019
2Saturday2/23/2019

<tbody>
</tbody>

Thanks for any insight you have,
Bill
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
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
 

Billman101

New Member
Joined
Feb 14, 2019
Messages
9
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
Do you have numbers in every cell from A3 to the end of the column?
 

Billman101

New Member
Joined
Feb 14, 2019
Messages
9
Hi Fluff,

Thanks for help.

I've pasted a portion of my sheet below:

Component Asset Group Description (Level 7)WO NumberWO Status
2Sunday2/17/2019
26Monday2/18/2019
16Tuesday2/19/2019
17Wednesday2/20/2019
19Thursday2/21/2019
16Friday2/22/2019
2Saturday2/23/2019
<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> </tbody>

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,
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
Could you please answer my question? ;)
 

Billman101

New Member
Joined
Feb 14, 2019
Messages
9
Fluff,

No. As you can see in previous post Col. A only has numbers for each date.

Bill
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
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.
 

Billman101

New Member
Joined
Feb 14, 2019
Messages
9
Ok. No only every third cell down to the seventh (day). After that there is no data.

Again thanks,
Bill
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
If you run this
Code:
Sub chk()
   MsgBox Range("A" & Rows.Count).End(xlUp).Row
End Sub
What does the Msgbox say?
 

Forum statistics

Threads
1,082,316
Messages
5,364,491
Members
400,802
Latest member
RichBRich

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top