Copy and Insert Rows - Use Dynamic Range and Paste to First Blank

sbmaurer

New Member
Joined
Dec 12, 2011
Messages
25
Hello,

Am currently an intern and a VBA newbie. Looking to write a code that inserts rows from one master template sheet and enters them into another interview sheet.

The template may change and this process needs to be repeated a certain number of times. (this number is set of certain cells that are filled in and hope to make the copy paste loop in the future)

For now what I looking for help on is.

Selecting the rows and inserting them with formats and formulas into the first blank cell in a range.

Here is my code, it is not working on the very last line?
Code:
Sub Copy_And_InsertRows_From_One_Sheet_To_Another()LastRow = Range("B" & Rows.Count).End(xlUp).Row + 1


With Worksheets("Score_Template")
Range("B10").Select
Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).EntireRow.Select
Application.CutCopyMode = False
Selection.Copy
End With
Worksheets("Interview_Card").Range("B" & LastRow).Select
Selection.Insert


End Sub

I can post files if anyone can help.

Thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Perhaps it would help if you could post your file.
 
Upvote 0
Hello,

Apparently I can not attach a file? Can anyone tell me how to post a file? Some further information is below.

Want to take the information from range B10:M18 (this range can change) on "Score_Template." and insert the rows along with their formulas and formats into the first blank under B10 on "Interview_Card."

Code below, appreciate any help!

Code:
Sub Copy_And_InsertRows_From_One_Sheet_To_Another()


LastRow = Range("B" & Rows.Count).End(xlUp).Row + 1


With Worksheets("Score_Template")


Range("B10").Select
Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).EntireRow.Select
Application.CutCopyMode = False
Selection.Copy
End With


Worksheets("Interview_Card").Range("B" & LastRow).Select
Selection.Insert


End Sub



Have been having issues:
1) inserting the entire rows, have been able to paste the data, but want to insert so it doesn't paste over values below.
2) copy the formulas, if I record a macro and copy and insert it keeps the formulas in line, such as on "Score_Template" when I copy and paste from range B10:M18 cell H11 is set to =G11. If I use cose to paste formulas on the new sheet it keeps "=G11", when I use copy and paste with a macro recorder it changes to "=G19" which is its new position in the range B19:L28.
3)
 
Upvote 0
You could upload your file to a free service at www.box.com or other similar website. After you register and upload your file, you will be given a link to that file. Post the link in this forum and then your file can be downloaded.
 
Upvote 0
Try this code. In your file, you have changed the height of most of the rows. You may have to re-adjust the height. This macro will copy the range B10 to M18 below the existing data in the Interview_Card sheet each time you run it. It will also copy the formulas and adjust the ranges automatically. If you want more space between the copies, just change the Offset number. At present, it will put 6 blanks rows in between. Hopefully, this is what you were looking for.

Code:
Sub CopyData()
    Dim bottomK As Integer
    bottomK = Sheets("Score_Template").Range("K" & Rows.Count)
    Sheets("Score_Template").Range("B10:M18").Copy Sheets("Interview_Card").Cells(Rows.Count, "B").End(xlUp).Offset(6, 0)
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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