Copy and Paste multiple rows within a range

demitri

New Member
Joined
Mar 2, 2010
Messages
7
I need help writing a macro to automate a specific set of actions. I have a range of multiple rows containing various component data (product description, quantity, unit pricing, and total pricing) for a specific product. At the bottom of the section, I have a summary with totals.

Component TypeComponent DescriptionQTYUnit CostTotal Cost
Product A
Component 1
Component 2
Component 3
Component 4
Component 5
Component 6
Component 7
Component 8
Pricing Summary

<tbody>
</tbody>


I want the macro to add a new Product (Product B) by copying and pasting all of the rows in Product A -- including the header -- two lines below the last component of Product A to create spacing between products.
When I run the macro again, it should create a new product (Product C) by copying and pasting all of the rows in Product B two lines below Product B and so on.

Any help on this is much appreciated.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I need help writing a macro to automate a specific set of actions. I have a range of multiple rows containing various component data (product description, quantity, unit pricing, and total pricing) for a specific product. At the bottom of the section, I have a summary with totals.

Component TypeComponent DescriptionQTYUnit CostTotal Cost
Product A
Component 1
Component 2
Component 3
Component 4
Component 5
Component 6
Component 7
Component 8
Pricing Summary

<tbody>
</tbody>


I want the macro to add a new Product (Product B) by copying and pasting all of the rows in Product A -- including the header -- two lines below the last component of Product A to create spacing between products.
When I run the macro again, it should create a new product (Product C) by copying and pasting all of the rows in Product B two lines below Product B and so on.

Any help on this is much appreciated.

Hie Dimitri,

Do you want that once you run the macro it copy's component 1 to component 8 from column A and then paste it below component 8 of product a. Do you also want the header component type?
 
Upvote 0
Hie Dimitri,

Do you want that once you run the macro it copy's component 1 to component 8 from column A and then paste it below component 8 of product a. Do you also want the header component type?


Hi cpatel13,

Yes that's what I'm looking but I do not want to include the header.

Thanks in advance.
 
Upvote 0
Hie Dimitri,

Do you want that once you run the macro it copy's component 1 to component 8 from column A and then paste it below component 8 of product a. Do you also want the header component type?

hie,
so far what i understood please find the code, please bear in mind that the code works on the structure what you have provided here, so if there is any changes from what you have posted and the original file, the code may not work properly.

Code:
Sub LastRowInOneColumn()
'Find the last used row in a Column: column A in this example
    Dim LastRow As Long
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    Range("a" & LastRow - 2).Select
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.Offset(-1, 0).Select
    Range(ActiveCell, ActiveCell.Offset(-8, 0)).Copy
    ActiveCell.Offset(2, 0).PasteSpecial xlPasteValues
    ActiveCell.Offset(9, 0).Select
    ActiveCell.Clear
End Sub

If any doubts do contact.
 
Upvote 0
hie,
so far what i understood please find the code, please bear in mind that the code works on the structure what you have provided here, so if there is any changes from what you have posted and the original file, the code may not work properly.

Code:
Sub LastRowInOneColumn()
'Find the last used row in a Column: column A in this example
    Dim LastRow As Long
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    Range("a" & LastRow - 2).Select
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.Insert
    ActiveCell.Offset(-1, 0).Select
    Range(ActiveCell, ActiveCell.Offset(-8, 0)).Copy
    ActiveCell.Offset(2, 0).PasteSpecial xlPasteValues
    ActiveCell.Offset(9, 0).Select
    ActiveCell.Clear
End Sub

If any doubts do contact.


Thank you for this. I would like to expand this a bit because I have additional rows of data below what I initially provided and I should have been more clear. Because of the additional data below this section, when I run your code it finds the bottom most cell in column A and adds rows there. However, if this is the only data I had on my worksheet, this code would work great. I've attached a screen shot to show you a more accurate depiction of my sheet. Can you modify your initial code to accommodate this change?


2my3aq.png
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,519
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