Using VBA Macros to insert rows based on cell value

Xcels

New Member
Joined
Dec 15, 2022
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
Hi there,

I am trying to insert 3 rows based on cell value using a macro.

For example:
Starting from the last cell of column D, IF the last cell in column D = 2, I want to copy the entire row and paste it above 3 times. I would want to loop through the rows from bottom up and repeat only if the value in the cell of column D is = 2.

I would really appreciate the help!

Thanks,
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
So let say, there is 2 on row 10 then, moved to row 7.
While running, the code will find it again on row 7 and will want to move to row 4.

So the logical thing will be is to move 2 to row 7 and skip the step to row 6 but this time you will miss 9 and 8 for checking.

What should be the exact rule?
 
Upvote 0

Forum statistics

Threads
1,214,613
Messages
6,120,515
Members
448,968
Latest member
Ajax40

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