VBA Insert rows Offset

MCC123

New Member
Joined
Apr 17, 2019
Messages
13
Hi all, I need help figuring out how to insert rows in between other rows. I keep a locomotive periodic maintenance report, I have 3 rows and each row is for each locomotive one underneath the other. I need to be able to insert a row below each piece of equipment. I have a code that will do just that but it only works a few times and then starts inserting rows where I don't need it. I'm very new at this and do not know all the proper terminology. Please see example below. My problem is when hit command button a few times it will only insert new lines below the 601 and 602. I need continuous data therefore I need to keep inserting lines below the 601, 602, 603. Thanks in advance! The Data spans from Column b to column T and rows 14 15 and 16.

Beginning before I hit the command button
601
10/17/2018
1/16/2019
4/6/2019
4/26/2018
4/17/2019
4/26/2017
1/17/2018
1/16/2019
1/17/2018
1/16/2019
1/17/2018
1/16/2019
4/5/2017
602
11/7/2018
2/5/2019
5/1/2019
6/6/2018
6/6/2019
6/6/2018
2/7/2018
2/5/2019
2/7/2018
2/5/2019
2/7/2018
2/5/2019
4/4/2017
5/1/2019
603
12/5/2018
3/6/2019
6/5/2019
8/3/2019
8/2/2016
2/7/2018
3/6/2019
3/7/2018
3/6/2019
3/7/2018
3/6/2019
4/3/2017
6/5/209


<tbody>
</tbody>

After I hit the command button
601
10/17/2018
1/16/2019
4/6/2019
4/26/2018
4/17/2019
4/26/2017
1/17/2018
1/16/2019
1/17/2018
1/16/2019
1/17/2018
1/16/2019
4/5/2017
4/17/2019
1/16/2019
1/16/2019
1/16/2019
602
11/7/2018
2/5/2019
5/1/2019
6/6/2018
6/6/2019
6/6/2018
2/7/2018
2/5/2019
2/7/2018
2/5/2019
2/7/2018
2/5/2019
4/4/2017
5/1/2019
6/6/2019
2/5/2019
2/5/2019
2/5/2019
5/1/2019
603
12/5/2018
3/6/2019
6/5/2019
8/3/2019
8/2/2016
2/7/2018
3/6/2019
3/7/2018
3/6/2019
3/7/2018
3/6/2019
4/3/2017
6/5/2019
3/6/2019
3/6/2019
3/6/2019
6/5/2019

<tbody>
</tbody>
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I am not able to see what you want.

You said insert Rows.

But normally when you insert a row the new row will be empty.

But that is not the case in your example.

You may be inserting cells but not a row

A row involves the entire row.

Inserting cells and rows are not the same.
 
Upvote 0
In your image 4/17/2019 was first in column 6 but after insert was in column 5
 
Last edited:
Upvote 0
I have a copy paste function in my code because there are certain cells that I need to copy the value in when I insert a new row. I just need help with a code that will insert a row once I hit my command button. This report spans the whole year and at the end of the year It will add or insert a row to each 601 - 602 - 603 - With the code I have it will only work a few times - I need to be able to insert a row to each sub header after the beginning of each year.

This is after I hit the command button 3 times - The 1st time it inserted a row below 601 - 602 - 603 - the 2nd time it inserted another row below the last row added to the 601 - 602 - the 3rd time it inserted rows below just the 601. It needs to be able to insert a row below the last row inserted in each the 601 - 602 - 603
601
602
603
<colgroup><col width="64" style="width: 48pt;"> <col width="77" style="width: 58pt; mso-width-source: userset; mso-width-alt: 2816;"> <col width="85" style="width: 64pt; mso-width-source: userset; mso-width-alt: 3108;"> <col width="68" style="width: 51pt; mso-width-source: userset; mso-width-alt: 2486;"> <col width="69" style="width: 52pt; mso-width-source: userset; mso-width-alt: 2523;" span="2"> <col width="75" style="width: 56pt; mso-width-source: userset; mso-width-alt: 2742;"> <col width="80" style="width: 60pt; mso-width-source: userset; mso-width-alt: 2925;" span="2"> <col width="87" style="width: 65pt; mso-width-source: userset; mso-width-alt: 3181;"> <col width="101" style="width: 76pt; mso-width-source: userset; mso-width-alt: 3693;"> <col width="73" style="width: 55pt; mso-width-source: userset; mso-width-alt: 2669;"> <col width="75" style="width: 56pt; mso-width-source: userset; mso-width-alt: 2742;"> <col width="68" style="width: 51pt; mso-width-source: userset; mso-width-alt: 2486;" span="4"> <col width="64" style="width: 48pt;" span="2"> <tbody> </tbody>
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

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